public TransactionTable UpdateItems(WebProperties WebProps, DataTable Items, IntegrationLog Log)
        {
            CheckArgumentForNull(WebProps, nameof(WebProps));
            CheckArgumentForNull(Items, nameof(Items));
            CheckArgumentForNull(Log, nameof(Log));

            const string queryTemplate = "SELECT * FROM {0} WHERE {1}=@id";
            var          tableName     = WebProps.Properties[PropKeyTable];
            var          idColumn      = WebProps.Properties[PropKeyIdColumn];
            var          trans         = new TransactionTable();

            using (var connection = GetConnection(WebProps.Properties))
            {
                connection.Open();

                foreach (DataRow drItem in Items.Rows)
                {
                    var currentId = drItem[ColNameId].ToString();
                    var spId      = drItem[ColNameSpid].ToString();

                    try
                    {
                        if (currentId == string.Empty)
                        {
                            trans.AddRow(spId, InsertRow(WebProps, drItem, Log, connection), TransactionType.INSERT);
                        }
                        else
                        {
                            var dataSet = new DataSet();
                            using (var command = new SqlCommand(string.Format(queryTemplate, tableName, idColumn), connection))
                            {
                                command.Parameters.AddWithValue("@id", currentId);

                                using (var dataAdapter = new SqlDataAdapter(command))
                                {
                                    dataAdapter.Fill(dataSet);
                                }
                            }

                            if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
                            {
                                trans.AddRow(spId, UpdateRow(WebProps, drItem, Log, connection), TransactionType.UPDATE);
                            }
                            else
                            {
                                trans.AddRow(spId, InsertRow(WebProps, drItem, Log, connection), TransactionType.INSERT);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(ex.ToString());
                        Log.LogMessage(ex.Message, IntegrationLogType.Error);
                        trans.AddRow(spId, currentId, TransactionType.FAILED);
                    }
                }
            }

            return(trans);
        }
 private IEnumerable <IntegrationLog> CreateIntegrationLog(KeyEventWrapper originalKeyEvents, KeyEventResponse response)
 {
     try
     {
         IList <IntegrationLog> logs = new List <IntegrationLog>();
         foreach (var item in originalKeyEvents.KeyEvents)
         {
             try
             {
                 IntegrationLog _log = new IntegrationLog();
                 _log.DateTimeSent            = response.RequestSentDateTime;
                 _log.IsSuccessFlg            = response.IsSuccessful;
                 _log.KeyEventId              = item.KeyEventId;
                 _log.RequestJsonDatainString = response.RequestJsonString;
                 _log.ResponseDescription     = response.ResponseMessage;
                 _log.ResponseReceivedinSecs  = response.ResponseTimeinSecs;
                 logs.Add(_log);
             }
             catch (Exception ex)
             {
                 LogWrapper.Log($"Error in generating Integration log for KeyeventId {item.KeyEventId}. Error is {ex.Message}. Skipping to next one", $"Thread id : {System.Threading.Thread.CurrentThread.ManagedThreadId}", 1, System.Diagnostics.TraceEventType.Error);
             }
         }
         return(logs as IEnumerable <IntegrationLog>);
     }
     catch (Exception ex)
     {
         LogWrapper.Log($"Error in generating Integration log. Error is {ex.Message}", $"Thread id : {System.Threading.Thread.CurrentThread.ManagedThreadId}", 1, System.Diagnostics.TraceEventType.Error);
         return(null);
     }
 }
Example #3
0
        private bool BuildWSDL(WebProperties WebProps, IntegrationLog Log)
        {
            try
            {
                Uri uri = new Uri(WebProps.Properties["WSDL"].ToString());
                //byte[] byteArray = Encoding.ASCII.GetBytes(WebProps.Properties["WSDL"].ToString());
                //MemoryStream stream = new MemoryStream(byteArray);
                WebRequest       webRequest = WebRequest.Create(uri);
                System.IO.Stream stream     = webRequest.GetResponse().GetResponseStream();

                ServiceDescription sd     = ServiceDescription.Read(stream);
                string             sdName = sd.Services[0].Name;

                // Initialize a service description servImport
                ServiceDescriptionImporter servImport = new ServiceDescriptionImporter();
                servImport.AddServiceDescription(sd, String.Empty, String.Empty);
                servImport.ProtocolName          = "Soap";
                servImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;

                CodeNamespace   nameSpace       = new CodeNamespace();
                CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
                codeCompileUnit.Namespaces.Add(nameSpace);

                ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit);

                if (warnings == 0)
                {
                    using (var stringWriter = new StringWriter(CultureInfo.CurrentCulture))
                    {
                        var prov = new CSharpCodeProvider();
                        prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions());

                        var assemblyReferences = new string[2] {
                            "System.Web.Services.dll", "System.Xml.dll"
                        };
                        var param = new CompilerParameters(assemblyReferences)
                        {
                            GenerateExecutable    = false,
                            GenerateInMemory      = true,
                            TreatWarningsAsErrors = false,
                            WarningLevel          = 4,
                        };

                        var results = new CompilerResults(new TempFileCollection());
                        results = prov.CompileAssemblyFromDom(param, codeCompileUnit);
                        var assembly = results.CompiledAssembly;
                        service = assembly.GetType(sdName);

                        methodInfo = service.GetMethods();
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.LogMessage(ex.Message, IntegrationLogType.Error);
            }
            return(false);
        }
Example #4
0
        public DataTable PullData(WebProperties WebProps, IntegrationLog Log, DataTable Items, DateTime LastSynch)
        {
            DataTable dt = new DataTable();


            return(dt);
        }
        public List <ColumnProperty> GetColumns(WebProperties WebProps, IntegrationLog Log, string ListName)
        {
            CheckArgumentForNull(WebProps, nameof(WebProps));
            CheckArgumentForNull(ListName, nameof(ListName));

            const string queryTemplate = "select name from sys.columns where object_id = object_id('{0}')";
            var          tableName     = WebProps.Properties[PropKeyTable].ToString().Replace(Apostrophe, DoubleApostrophe);

            var columnsList = new List <ColumnProperty>();


            using (var connection = GetConnection(WebProps.Properties))
            {
                connection.Open();

                using (var command = new SqlCommand(string.Format(queryTemplate, tableName), connection))
                    using (var dataReader = command.ExecuteReader())
                    {
                        while (dataReader.Read())
                        {
                            var colProperty = new ColumnProperty();
                            colProperty.ColumnName        = dataReader.GetString(0);
                            colProperty.DiplayName        = dataReader.GetString(0);
                            colProperty.DefaultListColumn = GetDefaultColumn(ListName, dataReader.GetString(0));
                            columnsList.Add(colProperty);
                        }
                    }
            }

            return(columnsList);
        }
        public List <ColumnProperty> GetColumns(WebProperties webProps, IntegrationLog log, string listName)
        {
            var columnProperties = new List <ColumnProperty>();

            try
            {
                O365Service o365Service = GetO365Service(webProps);

                var ignoredFields = new[]
                {
                    "AppAuthor", "AppEditor", "Attachments", "DocIcon",
                    "ItemChildCount", "FolderChildCount", "_UIVersionString"
                };

                columnProperties.AddRange(
                    from field in o365Service.GetListFields(webProps.Properties["List"].ToString())
                    let internalName = field.InternalName
                                       where !ignoredFields.Contains(internalName) &&
                                       !internalName.StartsWith("LinkTitle") && !internalName.EndsWith("NoMenu")
                                       orderby field.Title
                                       select new ColumnProperty
                {
                    ColumnName        = internalName,
                    DiplayName        = field.Title,
                    type              = TranslateFieldType(field.FieldTypeKind),
                    DefaultListColumn = GetMatchingListColumn(internalName)
                });
            }
            catch (Exception e)
            {
                log.LogMessage(e.Message, IntegrationLogType.Error);
            }

            return(columnProperties);
        }
        public Dictionary <string, string> GetDropDownValues(WebProperties webProps, IntegrationLog log, string property,
                                                             string parentPropertyValue)
        {
            var dictionary = new Dictionary <string, string>();

            try
            {
                SfService sfService = GetSfService(webProps);

                if (property.Equals("Object"))
                {
                    dictionary = sfService.GetIntegratableObjects();
                }
                else if (property.Equals("UserMapType"))
                {
                    return new Dictionary <string, string> {
                               { "Email", "Email" }
                    }
                }
                ;

                throw new Exception("Invalid property: " + property);
            }
            catch (Exception e)
            {
                log.LogMessage(e.Message, IntegrationLogType.Error);
            }

            return(dictionary);
        }
        public bool TestConnection(WebProperties webProps, IntegrationLog log, out string message)
        {
            message = string.Empty;

            try
            {
                O365Service o365Service = GetO365Service(webProps);
                if (!o365Service.EnsureEPMLiveAppInstalled())
                {
                    log.LogMessage(
                        "Please make sure that you have installed the EPM Live app in your Office 365 environment.",
                        IntegrationLogType.Error);

                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                message = e.Message;
                log.LogMessage(message, IntegrationLogType.Error);

                return(false);
            }
        }
        public bool InstallIntegration(WebProperties webProps, IntegrationLog log, out string message,
                                       string integrationKey,
                                       string apiUrl)
        {
            message = string.Empty;

            try
            {
                O365Service o365Service = GetO365Service(webProps);

                o365Service.InstallIntegration(webProps.IntegrationId, integrationKey, apiUrl, webProps.Title,
                                               webProps.FullURL, webProps.EnabledFeatures,
                                               (string)webProps.Properties["List"],
                                               bool.Parse((string)webProps.Properties["AllowAddInt"]),
                                               bool.Parse((string)webProps.Properties["AllowAddList"]),
                                               bool.Parse((string)webProps.Properties["AllowDeleteInt"]));

                return(true);
            }
            catch (Exception e)
            {
                message = e.Message;
            }

            return(false);
        }
Example #10
0
        public TransactionTable UpdateItems(WebProperties WebProps, DataTable Items, IntegrationLog Log)
        {
            TransactionTable trans = new TransactionTable();

            if (BuildWSDL(WebProps, Log))
            {
                MethodInfo Method = null;

                foreach (MethodInfo t in methodInfo)
                {
                    if (t.Name == WebProps.Properties["WSDLFunction"].ToString())
                    {
                        Method = t;
                        param  = t.GetParameters();
                        break;
                    }
                }

                if (Method != null)
                {
                    foreach (DataRow drItem in Items.Rows)
                    {
                        try
                        {
                            Hashtable hshProps = GetItemHash(WebProps, drItem);

                            object[] param1 = new object[param.Length];

                            int i = 0;

                            foreach (var p in param)
                            {
                                param1[i++] = Convert.ChangeType(hshProps[p.Name], p.ParameterType);
                            }

                            Object obj      = Activator.CreateInstance(service);
                            Object response = Method.Invoke(obj, param1);
                            try
                            {
                                if (WebProps.Properties["LogInfo"].ToString() == "True")
                                {
                                    Log.LogMessage("WSDL Response: " + response.ToString(), IntegrationLogType.Information);
                                }
                            }
                            catch { }
                        }
                        catch (Exception ex)
                        {
                            Log.LogMessage("Error sending item (" + drItem["SPID"].ToString() + "): " + ex.Message, IntegrationLogType.Error);
                        }
                    }
                }
                else
                {
                    Log.LogMessage("Could not find method", IntegrationLogType.Error);
                }
            }
            return(trans);
        }
 public void TestInitialize()
 {
     _shimsContext      = ShimsContext.Create();
     _testEntity        = new SQL();
     _testEntityPrivate = new PrivateObject(_testEntity);
     _adoShims          = AdoShims.ShimAdoNetCalls();
     _logger            = new IntegrationLog(null, Guid.Empty, Guid.Empty, string.Empty);
 }
        // Public Methods (9) 

        public TransactionTable DeleteItems(WebProperties webProps, DataTable items, IntegrationLog log)
        {
            var transactionTable = new TransactionTable();

            try
            {
                if (!bool.Parse((string)webProps.Properties["AllowDeleteInt"]))
                {
                    throw new Exception("Office 365 delete is not allowed.");
                }

                O365Service o365Service = GetO365Service(webProps);

                List <string> ids;
                Dictionary <string, string> idMap = BuildIdMap(items, out ids);

                int index = 0;

                foreach (
                    O365Result result in
                    o365Service.DeleteListItemsById(ids.ToArray(), (string)webProps.Properties["List"]))
                {
                    string o365Id = result.ItemId.ToString();
                    string spid;

                    try
                    {
                        spid = idMap[o365Id];
                    }
                    catch
                    {
                        spid = items.Rows[index]["SPID"].ToString();
                    }

                    if (result.Success)
                    {
                        transactionTable.AddRow(spid, o365Id, TransactionType.DELETE);
                    }
                    else
                    {
                        transactionTable.AddRow(spid, o365Id, TransactionType.FAILED);
                        log.LogMessage(string.Format(
                                           "Could not delete record with Office 365 ID: {0}, SharePoint ID: {1}. Message: {2}",
                                           o365Id, spid, result.Error), IntegrationLogType.Warning);
                    }

                    index++;
                }
            }
            catch (Exception e)
            {
                log.LogMessage(e.Message, IntegrationLogType.Error);
            }

            return(transactionTable);
        }
Example #13
0
        public String getRoundNumber()
        {
            String response    = "";
            var    credentials = new NetworkCredential(inforConfig.username, inforConfig.password);
            var    handler     = new HttpClientHandler {
                Credentials = credentials
            };

            handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); };
            using (var client = new HttpClient(handler))
            {
                // Make your request...
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    HttpResponseMessage message = client.GetAsync(Config.General.urlInfor + "/OPS270MI/AddRoundNumber").Result;
                    if (message.IsSuccessStatusCode)
                    {
                        var    serializer = new DataContractJsonSerializer(typeof(InforRoundNumber));
                        var    result     = message.Content.ReadAsStringAsync().Result;
                        byte[] byteArray  = Encoding.UTF8.GetBytes(result);
                        //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
                        MemoryStream     stream     = new MemoryStream(byteArray);
                        InforRoundNumber resultData = serializer.ReadObject(stream) as InforRoundNumber;
                        try
                        {
                            response = resultData.results[0].records[0].ITRN;
                        }
                        catch (Exception ex)
                        {
                            IntegrationLog log = new IntegrationLog();
                            log.Description                 = "getRoundNumber";
                            log.ErrorMessage                = ex.ToString();
                            log.NrOfFailedTransactions      = 0;
                            log.NrOfSuccessfullTransactions = 0;
                            log.NumOfLineSubmited           = 0;
                            log.RefNumber       = "No Ref";
                            log.TransactionType = "Round Number Petty Cash";
                            _context.IntegrationLog.Add(log);
                            _context.SaveChanges();
                        }
                    }
                    else
                    {
                        response = "Fail";
                    }
                }
                catch (Exception ex)
                {
                    response = ex.ToString();
                }
                return(response);
            }
        }
        public TransactionTable UpdateItems(WebProperties webProps, DataTable items, IntegrationLog log)
        {
            var transactionTable = new TransactionTable();

            try
            {
                O365Service o365Service = GetO365Service(webProps);

                List <string> ids;
                Dictionary <string, string> idMap = BuildIdMap(items, out ids);

                int index = 0;

                foreach (
                    O365Result result in
                    o365Service.UpsertItems((string)webProps.Properties["List"], webProps.IntegrationId, items))
                {
                    string o365Id = result.ItemId.ToString();

                    string spId;

                    try
                    {
                        spId = idMap[o365Id];
                    }
                    catch
                    {
                        spId = items.Rows[index]["SPID"].ToString();
                    }

                    if (result.Success)
                    {
                        transactionTable.AddRow(spId, o365Id, result.TransactionType);
                    }
                    else
                    {
                        transactionTable.AddRow(spId, o365Id, TransactionType.FAILED);

                        log.LogMessage(string.Format(
                                           "Could not insert / update record with Office 365 ID: {0}, SharePoint ID: {1}. Message: {2}",
                                           o365Id, spId, result.Error), IntegrationLogType.Warning);
                    }

                    index++;
                }
            }
            catch (Exception e)
            {
                log.LogMessage(e.Message, IntegrationLogType.Error);
            }

            return(transactionTable);
        }
        public DataTable GetItem(WebProperties WebProps, IntegrationLog Log, string ItemID, DataTable Items)
        {
            CheckArgumentForNull(WebProps, nameof(WebProps));
            CheckArgumentForNull(ItemID, nameof(ItemID));
            CheckArgumentForNull(Items, nameof(Items));

            var tableName = WebProps.Properties[PropKeyTable];
            var idColumn  = WebProps.Properties[PropKeyIdColumn];

            const string queryTemplate = "SELECT * FROM {0} WHERE {1} = '{2}'";

            using (var connection = GetConnection(WebProps.Properties))
            {
                connection.Open();

                var dataSet = new DataSet();

                using (var command = new SqlCommand(string.Format(queryTemplate, tableName, idColumn, ItemID), connection))
                    using (var dataAdapter = new SqlDataAdapter(command))
                    {
                        dataAdapter.Fill(dataSet);
                    }

                if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
                {
                    var dataRow = dataSet.Tables[0].Rows[0];

                    var valuesArray = new ArrayList();
                    valuesArray.Add(ItemID);

                    foreach (DataColumn dataColumn in Items.Columns)
                    {
                        if (dataColumn.ColumnName != ColNameId)
                        {
                            if (dataRow[dataColumn.ColumnName] != null)
                            {
                                valuesArray.Add(dataRow[dataColumn.ColumnName].ToString());
                            }
                            else
                            {
                                valuesArray.Add(string.Empty);
                            }
                        }
                    }

                    Items.Rows.Add(valuesArray.OfType <string>().ToArray());
                }
            }

            return(Items);
        }
        public DataTable PullData(WebProperties WebProps, IntegrationLog Log, DataTable Items, DateTime LastSynch)
        {
            CheckArgumentForNull(WebProps, nameof(WebProps));
            CheckArgumentForNull(Items, nameof(Items));

            var dataSet = new DataSet();

            using (var connection = GetConnection(WebProps.Properties))
            {
                connection.Open();

                var colsBuilder = new StringBuilder(WebProps.Properties[PropKeyIdColumn].ToString());

                var where = WebProps.Properties.ContainsKey(PropKeyWhere)
                    ? WebProps.Properties[PropKeyWhere].ToString()
                    : string.Empty;

                foreach (DataColumn dataColumn in Items.Columns)
                {
                    if (dataColumn.ColumnName != ColNameId)
                    {
                        colsBuilder.Append($",{dataColumn.ColumnName}");
                    }
                }

                var query = $"SELECT {colsBuilder} FROM {WebProps.Properties[PropKeyTable]}";
                if (where != string.Empty)
                {
                    query = $"{query} Where {where.Replace(Apostrophe, DoubleApostrophe)}";
                }

                using (var command = new SqlCommand(query, connection))
                    using (var dataAdapter = new SqlDataAdapter(command))
                    {
                        dataAdapter.Fill(dataSet);
                    }
            }

            if (dataSet.Tables.Count == 0)
            {
                throw new InvalidOperationException("No tables returned from query");
            }

            var idColumn = WebProps.Properties[PropKeyIdColumn].ToString();

            dataSet.Tables[0].Columns[idColumn].ColumnName = ColNameId;

            return(dataSet.Tables[0]);
        }
Example #17
0
        public List <ColumnProperty> GetColumns(WebProperties WebProps, IntegrationLog Log, string ListName)
        {
            List <ColumnProperty> lstCols = new List <ColumnProperty>();

            string[] cols = WebProps.Properties["Fields"].ToString().Split(',');
            foreach (string col in cols)
            {
                ColumnProperty prop = new ColumnProperty();
                prop.ColumnName = col;
                prop.DiplayName = col;
                lstCols.Add(prop);
            }

            return(lstCols);
        }
 public bool TestConnection(WebProperties WebProps, IntegrationLog Log, out string Message)
 {
     try
     {
         Message = "";
         SqlConnection cn = GetConnection(WebProps.Properties);
         cn.Open();
         cn.Close();
         return(true);
     }
     catch (Exception ex) {
         Message = "Error: " + ex.Message;
         return(false);
     }
 }
        public DataTable GetItem(WebProperties webProps, IntegrationLog log, string itemId, DataTable items)
        {
            try
            {
                SfService sfService = GetSfService(webProps);
                sfService.GetObjectItemsById((string)webProps.Properties["Object"], itemId, items);
            }
            catch (Exception e)
            {
                log.LogMessage(e.Message, e.Message.StartsWith("No records found")
                                              ? IntegrationLogType.Warning
                                              : IntegrationLogType.Error);
            }

            return(items);
        }
        public DataTable PullData(WebProperties webProps, IntegrationLog log, DataTable items, DateTime lastSynch)
        {
            try
            {
                SfService sfService = GetSfService(webProps);
                sfService.GetObjectItems((string)webProps.Properties["Object"], items, lastSynch);
            }
            catch (Exception e)
            {
                log.LogMessage("Scheduled Pull. " + e.Message, e.Message.StartsWith("No records found")
                                                                   ? IntegrationLogType.Warning
                                                                   : IntegrationLogType.Error);
            }

            return(items);
        }
        private string InsertRow(WebProperties WebProps, DataRow Item, IntegrationLog Log, SqlConnection cn)
        {
            string paramnames  = "";
            string paramvalues = "";

            ArrayList arrparams = new ArrayList();

            foreach (DataColumn dc in Item.Table.Columns)
            {
                if (dc.ColumnName != "ID" && dc.ColumnName != "SPID")
                {
                    paramnames  += dc.ColumnName + ",";
                    paramvalues += "@" + dc.ColumnName + ",";
                    if (Item[dc.ColumnName].ToString() == "")
                    {
                        arrparams.Add(new SqlParameter("@" + dc.ColumnName, DBNull.Value));
                    }
                    else
                    {
                        arrparams.Add(new SqlParameter("@" + dc.ColumnName, Item[dc.ColumnName].ToString()));
                    }
                }
            }

            try
            {
                if (WebProps.Properties["SPColumn"].ToString() != "")
                {
                    paramnames  += WebProps.Properties["SPColumn"] + ",";
                    paramvalues += "@" + WebProps.Properties["SPColumn"] + ",";
                    arrparams.Add(new SqlParameter("@" + WebProps.Properties["SPColumn"], Item["SPID"].ToString()));
                }
            }
            catch { }

            string sql = "INSERT INTO " + WebProps.Properties["Table"] + "(" + paramnames.Trim(',') + ") OUTPUT Inserted." + WebProps.Properties["IDColumn"] + " VALUES (" + paramvalues.Trim(',') + ")";

            object result;

            using (var command = new SqlCommand(sql, cn))
            {
                command.Parameters.AddRange(arrparams.ToArray(typeof(SqlParameter)));
                result = command.ExecuteScalar();
            }

            return(result?.ToString());
        }
        public bool RemoveIntegration(WebProperties webProps, IntegrationLog log, out string message,
                                      string integrationKey)
        {
            message = string.Empty;

            try
            {
                SfService sfService = GetSfService(webProps);
                sfService.UninstallIntegration(integrationKey, webProps.Properties["Object"].ToString());
            }
            catch (Exception e)
            {
                message = e.Message;
            }

            return(true);
        }
Example #23
0
        public Dictionary <String, String> GetDropDownValues(WebProperties WebProps, IntegrationLog log, string Property, string ParentPropertyValue)
        {
            Dictionary <string, string> props = new Dictionary <string, string>();

            switch (Property)
            {
            case "UserMapType":
                props.Add("Email", "Email Address");
                props.Add("Username", "Username");
                props.Add("SPID", "SharePoint User ID");
                break;

            case "AvailableSynchOptions":
                props.Add("LI", "LI");
                try
                {
                    if (WebProps.Properties["WSDL"].ToString().Length > 0)
                    {
                        props.Add("LO", "LO");
                        props.Add("TI", "TI");
                    }
                }
                catch { }
                break;

            case "WSDLFunction":
                if (BuildWSDL(WebProps, log))
                {
                    foreach (MethodInfo t in methodInfo)
                    {
                        if (t.Name == "Discover")
                        {
                            break;
                        }
                        props.Add(t.Name, t.Name);
                    }
                }
                else
                {
                }
                break;
            }

            return(props);
        }
        public bool TestConnection(WebProperties webProps, IntegrationLog log, out string message)
        {
            message = string.Empty;

            try
            {
                SfService sfService = GetSfService(webProps);
                sfService.EnsureEPMLiveAppInstalled();

                return(true);
            }
            catch (Exception e)
            {
                message = e.Message;
            }

            return(false);
        }
        private string UpdateRow(WebProperties WebProps, DataRow Item, IntegrationLog Log, SqlConnection cn)
        {
            string paramnames = "";

            ArrayList arrparams = new ArrayList();

            foreach (DataColumn dc in Item.Table.Columns)
            {
                if (dc.ColumnName != "ID" && dc.ColumnName != "SPID")
                {
                    paramnames += dc.ColumnName + " = @" + dc.ColumnName + ",";
                    if (Item[dc.ColumnName].ToString() == "")
                    {
                        arrparams.Add(new SqlParameter("@" + dc.ColumnName, DBNull.Value));
                    }
                    else
                    {
                        arrparams.Add(new SqlParameter("@" + dc.ColumnName, Item[dc.ColumnName].ToString()));
                    }
                }
            }

            try
            {
                if (WebProps.Properties["SPColumn"].ToString() != "")
                {
                    paramnames += WebProps.Properties["SPColumn"] + " = @" + WebProps.Properties["SPColumn"] + ",";
                    arrparams.Add(new SqlParameter("@" + WebProps.Properties["SPColumn"], Item["SPID"].ToString()));
                }
            }
            catch { }

            string sql = "UPDATE " + WebProps.Properties["Table"] + " Set " + paramnames.Trim(',') + " WHERE " + WebProps.Properties["IDColumn"] + " =@id";

            using (var command = new SqlCommand(sql, cn))
            {
                command.Parameters.AddRange(arrparams.ToArray(typeof(SqlParameter)));
                command.Parameters.AddWithValue("@id", Item[ColNameId].ToString());
                command.ExecuteScalar();
            }

            return(Item[ColNameId].ToString());
        }
        public Dictionary <String, String> GetDropDownValues(WebProperties WebProps, IntegrationLog log, string Property, string ParentPropertyValue)
        {
            CheckArgumentForNull(WebProps, nameof(WebProps));
            CheckArgumentForNull(Property, nameof(Property));

            var properties = new Dictionary <string, string>();

            using (var connection = GetConnection(WebProps.Properties))
            {
                connection.Open();

                switch (Property)
                {
                case PropKeyTable:
                    using (var command = new SqlCommand("select name from sys.tables", connection))
                        using (var dataReader = command.ExecuteReader())
                        {
                            while (dataReader.Read())
                            {
                                properties.Add(dataReader.GetString(0), dataReader.GetString(0));
                            }
                        }
                    break;

                case PropKeyUserMapType:
                    properties.Add("Email", "Email Address");
                    break;

                case PropKeyAvailableSyncOpts:
                    properties.Add("LI", "LI");
                    properties.Add("TI", "TI");
                    properties.Add("TO", "TO");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(Property), "Unexpected value from Property argument");
                }
            }

            return(properties);
        }
        public bool RemoveIntegration(WebProperties webProps, IntegrationLog log, out string message,
                                      string integrationKey)
        {
            message = string.Empty;

            try
            {
                O365Service o365Service = GetO365Service(webProps);
                o365Service.UninstallIntegration(integrationKey, webProps.IntegrationId);

                return(true);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("List 'EPMLiveIntegrations' does not exist"))
                {
                    return(true);
                }
                message = e.Message;
            }

            return(false);
        }
        public TransactionTable DeleteItems(WebProperties WebProps, DataTable Items, IntegrationLog Log)
        {
            CheckArgumentForNull(WebProps, nameof(WebProps));
            CheckArgumentForNull(Items, nameof(Items));

            const string deleteCommandTemplate = "DELETE FROM {0} WHERE {1}=@id";
            var          tableName             = WebProps.Properties[PropKeyTable];
            var          idColumn = WebProps.Properties[PropKeyIdColumn];

            var table = new TransactionTable();

            using (var connection = GetConnection(WebProps.Properties))
            {
                connection.Open();

                foreach (DataRow dataRow in Items.Rows)
                {
                    try
                    {
                        using (var command = new SqlCommand(string.Format(deleteCommandTemplate, tableName, idColumn), connection))
                        {
                            command.Parameters.AddWithValue("@id", dataRow[ColNameId].ToString());
                            command.ExecuteNonQuery();
                        }

                        table.AddRow(dataRow[ColNameSpid].ToString(), dataRow[ColNameId].ToString(), TransactionType.DELETE);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(ex.ToString());
                        table.AddRow(dataRow[ColNameSpid].ToString(), dataRow[ColNameId].ToString(), TransactionType.FAILED);
                    }
                }
            }

            return(table);
        }
        public List <ColumnProperty> GetColumns(WebProperties webProps, IntegrationLog log, string listName)
        {
            var columnProperties = new List <ColumnProperty>();

            try
            {
                SfService sfService = GetSfService(webProps);

                var ignoredFields = new[]
                {
                    "IsDeleted", "CreatedDate", "LastModifiedDate",
                    "LastModifiedById", "SystemModstamp", "LastActivityDate",
                    sfService.AppNamespace + "__Additional_Assigned_To__c",
                    sfService.AppNamespace + "__FK__c"
                };

                columnProperties.AddRange(
                    from field in sfService.GetObjectFields(webProps.Properties["Object"].ToString())
                    where !ignoredFields.Contains(field.name)
                    orderby field.name
                    select new ColumnProperty
                {
                    ColumnName        = field.name,
                    DiplayName        = field.label,
                    type              = TranslateFieldType(field.type),
                    DefaultListColumn =
                        GetMatchingListColumn(field.label, field.name, sfService.AppNamespace)
                });
            }
            catch (Exception e)
            {
                log.LogMessage(e.Message, IntegrationLogType.Error);
            }

            return(columnProperties);
        }
Example #30
0
        public async Task <String> postPettyCash([FromBody] PettyCash transaction, int id, String roundNumberParam)
        {
            var credentials = new NetworkCredential(inforConfig.username, inforConfig.password);
            var handler     = new HttpClientHandler {
                Credentials = credentials
            };

            handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); };
            String status      = "";
            String roundNumber = roundNumberParam;

            using (var client = new HttpClient(handler))
            {
                // Make your request...
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    InforPettyCash inforObjTrans = new InforPettyCash();
                    inforObjTrans.program = "OPS270MI";
                    List <TransactionPettyCash> listTransaction = new List <TransactionPettyCash>();
                    for (int i = 0; i < transaction.pettyCashLine.Count; i++)
                    {
                        TransactionPettyCash t = new TransactionPettyCash();
                        t.transaction = "AddSlsTicketLin";
                        RecordPettyCash record = new RecordPettyCash();
                        record.CONO = "770";
                        record.DIVI = "AAA";
                        record.XRCD = "7000";
                        record.ITRN = roundNumber;
                        record.WHLO = transaction.storeCode;
                        record.ORNO = "PC" + id + "";
                        record.DLIX = "1";
                        record.PONR = (i + 1) + "";
                        record.POSX = "00";
                        record.CUCD = "IDR";
                        record.CUNO = transaction.customerIdStore;
                        record.ITNO = transaction.expenseCategoryId;
                        record.TRDT = DateTime.Now.ToString("yyyyMMdd");
                        record.TRTM = DateTime.Now.ToString("HHmmss");//"113000";
                        record.CUAM = transaction.pettyCashLine[i].total + "";
                        record.CSHC = "CSH";
                        record.VTCD = "0";
                        record.PYCD = "CSH";
                        record.ALUN = "PCS";

                        record.IVQA = transaction.pettyCashLine[i].quantity + "";
                        record.REFE = transaction.pettyCashLine[i].expenseName;
                        record.INYR = DateTime.Now.Year + "";
                        record.VTP1 = 0 + "";
                        record.ARAT = 1 + "";
                        record.CRTP = 1 + "";

                        t.record = record;
                        listTransaction.Add(t);
                    }

                    //sales ticket line



                    inforObjTrans.transactions = listTransaction;
                    HttpResponseMessage message = await client.PostAsJsonAsync(General.urlInfor, inforObjTrans);

                    if (message.IsSuccessStatusCode)
                    {
                        status = message.ToString();
                        var                serializer = new DataContractJsonSerializer(typeof(InforObjPostReturn));
                        var                result     = message.Content.ReadAsStringAsync().Result;
                        byte[]             byteArray  = Encoding.UTF8.GetBytes(result);
                        MemoryStream       stream     = new MemoryStream(byteArray);
                        InforObjPostReturn resultData = serializer.ReadObject(stream) as InforObjPostReturn;
                        //  status = "Return : " + resultData.results[0].errorMessage + "Sukses "+ resultData.nrOfSuccessfullTransactions;
                        IntegrationLog log = new IntegrationLog();
                        log.Description                 = transaction.pettyCashId;
                        log.ErrorMessage                = resultData.results[0].errorMessage;
                        log.NrOfFailedTransactions      = resultData.nrOfFailedTransactions;
                        log.NrOfSuccessfullTransactions = resultData.nrOfSuccessfullTransactions;
                        log.NumOfLineSubmited           = listTransaction.Count;
                        log.RefNumber       = transaction.pettyCashId + "";
                        log.Json            = JsonConvert.SerializeObject(inforObjTrans);
                        log.TransactionType = "OPS270MI-PettyCashTcktLine";
                        _context.IntegrationLog.Add(log);
                        _context.SaveChanges();
                    }
                    else
                    {
                        status = "Failed : " + message.ToString();
                    }
                    //send ticket pay

                    List <TransactionPettyCash> listTransactionPay = new List <TransactionPettyCash>();
                    InforPettyCash inforObjPay = new InforPettyCash();
                    inforObjPay.program = "OPS270MI";
                    TransactionPettyCash tRansactionAddSlsTicketPay = new TransactionPettyCash();
                    tRansactionAddSlsTicketPay.transaction = "AddSlsTicketPay";
                    RecordPettyCash recordAddSlsTicketPayEDC2 = new RecordPettyCash();
                    recordAddSlsTicketPayEDC2.CONO = "770";
                    recordAddSlsTicketPayEDC2.DLIX = "1";
                    recordAddSlsTicketPayEDC2.DIVI = "AAA";
                    recordAddSlsTicketPayEDC2.XRCD = "7090";
                    recordAddSlsTicketPayEDC2.ITRN = roundNumber;
                    recordAddSlsTicketPayEDC2.WHLO = transaction.storeCode;
                    recordAddSlsTicketPayEDC2.ORNO = "PC" + id + "";
                    recordAddSlsTicketPayEDC2.PONR = (transaction.pettyCashLine.Count + 1) + "";
                    recordAddSlsTicketPayEDC2.POSX = "00";
                    recordAddSlsTicketPayEDC2.CUCD = "IDR";
                    recordAddSlsTicketPayEDC2.TRDT = DateTime.Now.ToString("yyyyMMdd");
                    recordAddSlsTicketPayEDC2.TRTM = DateTime.Now.ToString("HHmmss");//"113000";
                    recordAddSlsTicketPayEDC2.CUAM = transaction.totalExpense + "";
                    recordAddSlsTicketPayEDC2.PYCD = "CSH";
                    recordAddSlsTicketPayEDC2.REFE = transaction.expenseCategory;
                    recordAddSlsTicketPayEDC2.ARAT = "1";
                    recordAddSlsTicketPayEDC2.CRTP = "1";
                    recordAddSlsTicketPayEDC2.ALUN = "PCS";
                    recordAddSlsTicketPayEDC2.CSHC = "CSH";

                    tRansactionAddSlsTicketPay.record = recordAddSlsTicketPayEDC2;
                    listTransactionPay.Add(tRansactionAddSlsTicketPay);
                    inforObjPay.transactions = listTransactionPay;
                    HttpResponseMessage messagebatch = await client.PostAsJsonAsync(Config.General.urlInfor, inforObjPay);

                    if (messagebatch.IsSuccessStatusCode)
                    {
                        status = messagebatch.ToString();
                        var                serializer = new DataContractJsonSerializer(typeof(InforObjPostReturn));
                        var                result     = messagebatch.Content.ReadAsStringAsync().Result;
                        byte[]             byteArray  = Encoding.UTF8.GetBytes(result);
                        MemoryStream       stream     = new MemoryStream(byteArray);
                        InforObjPostReturn resultData = serializer.ReadObject(stream) as InforObjPostReturn;
                        //  status = "Return : " + resultData.results[0].errorMessage + "Sukses "+ resultData.nrOfSuccessfullTransactions;
                        IntegrationLog log = new IntegrationLog();
                        log.Description                 = transaction.pettyCashId;
                        log.ErrorMessage                = resultData.results[0].errorMessage;
                        log.NrOfFailedTransactions      = resultData.nrOfFailedTransactions;
                        log.NrOfSuccessfullTransactions = resultData.nrOfSuccessfullTransactions;
                        log.NumOfLineSubmited           = listTransaction.Count;
                        log.RefNumber       = transaction.pettyCashId + "";
                        log.Json            = JsonConvert.SerializeObject(inforObjPay);
                        log.TransactionType = "OPS270MI-PettyCashTkcPay";
                        _context.IntegrationLog.Add(log);
                        _context.SaveChanges();
                    }
                    //end for pay

                    //send batch
                    //for auto batch
                    List <TransactionPettyCash> listTransactionbatch = new List <TransactionPettyCash>();
                    InforPettyCash inforObjBatch = new InforPettyCash();
                    inforObjBatch.program = "OPS270MI";
                    TransactionPettyCash tRansactionAddBatch = new TransactionPettyCash();
                    tRansactionAddBatch.transaction = "BchPrcRound";
                    RecordPettyCash recordRoundNumber = new RecordPettyCash();
                    recordRoundNumber.CONO     = "770";
                    recordRoundNumber.ITRN     = roundNumber;
                    recordRoundNumber.DIVI     = "AAA";
                    recordRoundNumber.TRDT     = DateTime.Now.ToString("yyyyMMdd");
                    recordRoundNumber.WHLO     = transaction.storeCode;
                    recordRoundNumber.ACDT     = DateTime.Now.ToString("yyyyMMdd");
                    tRansactionAddBatch.record = recordRoundNumber;
                    listTransactionbatch.Add(tRansactionAddBatch);
                    inforObjBatch.transactions = listTransactionbatch;
                    HttpResponseMessage messageTicketPay = await client.PostAsJsonAsync(Config.General.urlInfor, inforObjBatch);

                    if (messageTicketPay.IsSuccessStatusCode)
                    {
                        status = messageTicketPay.ToString();
                        var                serializer = new DataContractJsonSerializer(typeof(InforObjPostReturn));
                        var                result     = messageTicketPay.Content.ReadAsStringAsync().Result;
                        byte[]             byteArray  = Encoding.UTF8.GetBytes(result);
                        MemoryStream       stream     = new MemoryStream(byteArray);
                        InforObjPostReturn resultData = serializer.ReadObject(stream) as InforObjPostReturn;
                        //  status = "Return : " + resultData.results[0].errorMessage + "Sukses "+ resultData.nrOfSuccessfullTransactions;
                        IntegrationLog log = new IntegrationLog();
                        log.Description                 = transaction.pettyCashId;
                        log.ErrorMessage                = resultData.results[0].errorMessage;
                        log.NrOfFailedTransactions      = resultData.nrOfFailedTransactions;
                        log.NrOfSuccessfullTransactions = resultData.nrOfSuccessfullTransactions;
                        log.NumOfLineSubmited           = listTransaction.Count;
                        log.RefNumber       = transaction.pettyCashId + "";
                        log.Json            = JsonConvert.SerializeObject(inforObjBatch);
                        log.TransactionType = "OPS270MI-PettyCashBatch";
                        _context.IntegrationLog.Add(log);
                        _context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    status = ex.ToString();
                }
            }
            return(status);
        }