コード例 #1
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>IList{ProviderItem}.</returns>
        public override IList<ProviderItem> GetData(DataProviderContext context)
        {
            var query = Query.Replace(SpecialFieldNames.LAST_SUCCESS_DATE, LastSuccessDateParam);

            var result = new List<ProviderItem>();

            using (var cn = new OracleConnection(ConnectionString))
            {
                if (cn.State != ConnectionState.Open)
                    cn.Open();

                using (var cmd = new OracleCommand(query, cn))
                {
                    cmd.Parameters.Add(LastSuccessDateParam, context.LastSuccessDate.HasValue ? new OracleDate(context.LastSuccessDate.Value) : OracleDate.MinValue);

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var item = new ProviderItem();

                            for (var i = 0; i < reader.FieldCount; ++i)
                            {
                                item.Fields.Add(new ProviderFieldValue(i, reader.GetName(i), reader.IsDBNull(i) ? null : reader.GetValue(i)));
                            }

                            result.Add(item);
                        }
                    }
                }
            }

            return result;
        }
コード例 #2
0
ファイル: OleDbDataProvider.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>IList{ProviderItem}.</returns>
        public override IList<ProviderItem> GetData(DataProviderContext context)
        {
            var parameters = new List<OleDbParameter>();

            var query = Regex.Replace(
                Query,
                "~.*?~",
                m =>
                    {
                        switch (m.Value)
                        {
                            case SpecialFieldNames.LAST_SUCCESS_DATE:
                                {
                                    parameters.Add(
                                        context.LastSuccessDate.HasValue
                                            ? new OleDbParameter(string.Empty, context.LastSuccessDate.Value) { Scale = 3 }
                                            : new OleDbParameter(string.Empty, MinDateValue) { Scale = 3 });
                                }

                                break;

                            default:
                                throw new ArgumentException(string.Format("Unknown parameter name."), m.Value);
                        }

                        return "?";
                    });

            var result = new List<ProviderItem>();

            using (var cn = new OleDbConnection(ConnectionString))
            {
                if (cn.State != ConnectionState.Open)
                    cn.Open();

                using (var cmd = new OleDbCommand(query, cn))
                {
                    cmd.Parameters.AddRange(parameters.ToArray());

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var item = new ProviderItem();

                            for (var i = 0; i < reader.FieldCount; ++i)
                            {
                                item.Fields.Add(new ProviderFieldValue(i, reader.GetName(i), reader.IsDBNull(i) ? null : reader.GetValue(i)));
                            }

                            result.Add(item);
                        }
                    }
                }
            }

            return result;
        }
コード例 #3
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>IList{ProviderItem}.</returns>
        public IList<ProviderItem> GetData(DataProviderContext context)
        {
            var requestUri = new Uri(string.Format("{0}/{1}", Url, MethodName));
            var webRequest = (HttpWebRequest)WebRequest.Create(requestUri);

            webRequest.Method = "POST";
            webRequest.ProtocolVersion = HttpVersion.Version11;

            var parameters = new List<string>();

            foreach (var p in InputParameters)
            {
                var value = p.Value;

                value = value.Replace(SpecialFieldNames.LAST_SUCCESS_DATE, (context.LastSuccessDate.HasValue ? context.LastSuccessDate.Value : DateTime.MinValue).ToString("s"));

                parameters.Add(string.Format("{0}={1}", p.Name, value));
            }

            var parameterString = string.Join("&", parameters);
            var parameterData = Encoding.UTF8.GetBytes(parameterString);

            if (parameterData.Length > 0)
            {
                webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.ContentLength = parameterData.Length;
            }

            var requestStream = webRequest.GetRequestStream();

            if (parameterData.Length > 0)
            {
                requestStream.Write(parameterData, 0, parameterData.Length);
            }

            requestStream.Flush();
            requestStream.Close();

            return GetWebServiceResponse(webRequest);
        }
コード例 #4
0
ファイル: SyncProcessWorker.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="System.InvalidOperationException">No key fields were specified.</exception>
        public void Execute(JobExecutionContext context)
        {
            var startTime = DateTime.Now;

            Ioc.SatisfyImportsOnce(this);

            var processName = string.Empty;

            try
            {
                processName = GetProcessName(context);
                var isSuccessful = true;

                Logger.Log(
                    LogSeverity.Information,
                    "ESYNC",
                    string.Format(CultureInfo.InvariantCulture, "Process \"{0}\" synchronization started.", processName));

                var synchronizer = GetProcessSynchronizer(context);
                var session = CreateESyncSession(startTime, context);

                try
                {
                    var filterBuilders = CreateKeyFilterBuilders(synchronizer);
                    if (filterBuilders.Count == 0)
                        throw new InvalidOperationException("No key fields were specified.");

                    var fieldUpdaters = CreateFieldUpdaters(synchronizer);

                    var dpContext = new DataProviderContext();
                    var lastSuccessfulSession = GetLastSuccessfulSession(synchronizer);
                    if (lastSuccessfulSession != null)
                        dpContext.LastSuccessDate = lastSuccessfulSession.EndTime;

                    var data = GetData(synchronizer.DataProvider, dpContext);

                    session = LogItemsRetrieved(session, data.Count);

                    for (var i = 0; i < data.Count; ++i)
                    {
                        if (SyncServiceJob.IsStopped)
                        {
                            isSuccessful = false;
                            LogError(session, "The synchronization session was stopped.");
                            break;
                        }

                        var item = data[i];
                        var syncContext = new SynchronizationContext();

                        try
                        {
                            var result = Synchronize(synchronizer, filterBuilders, fieldUpdaters, item, syncContext);

                            isSuccessful = isSuccessful && result;

                            if (!result || syncContext.Errors.Count > 0 || syncContext.Warnings.Count > 0)
                            {
                                var description = GetDescription(syncContext);

                                Logger.Log(
                                    LogSeverity.Error,
                                    "ESYNC",
                                    string.Format(
                                        CultureInfo.InvariantCulture,
                                        "Synchronization failed for process \"{0}\", record {1}:{2}{3}",
                                        processName,
                                        i + 1,
                                        Environment.NewLine,
                                        description));

                                LogError(
                                    session,
                                    string.Format(CultureInfo.InvariantCulture, "Failed to synchronize record {0}.", i + 1),
                                    description,
                                    item);
                            }
                        }
                        catch (Exception ex)
                        {
                            isSuccessful = false;

                            Logger.Log(LogSeverity.Error, "ESYNC", ex);
                            LogError(session, string.Format(CultureInfo.InvariantCulture, "Failed to synchronize record {0}.", i + 1), ex.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    isSuccessful = false;
                    Logger.Log(LogSeverity.Error, "ESYNC", ex);
                    LogError(session, ex.Message, ex.ToString());
                }

                if (session != null)
                {
                    session.EndTime = DateTime.Now;
                    session.IsSuccessful = isSuccessful;
                    ((ISavable)session).Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogSeverity.Error, GetType().ToString(), ex);
            }
            finally
            {
                //Csla.ApplicationContext.User = new UnauthenticatedPrincipal();
                Logger.Log(LogSeverity.Information, "ESYNC", string.Format(CultureInfo.InvariantCulture, "Process \"{0}\" synchronization finished.", processName));
            }
        }
コード例 #5
0
ファイル: SyncProcessWorker.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="dataProvider">The data provider.</param>
        /// <param name="context">The context.</param>
        /// <returns>IList{ProviderItem}.</returns>
        /// <exception cref="Cebos.Veyron.SharedTypes.VeyronException">Failed to retrieve data.</exception>
        private static IList<ProviderItem> GetData(IDataProvider dataProvider, DataProviderContext context)
        {
            try
            {
                var data = dataProvider.GetData(context);

                return data ?? new List<ProviderItem>();
            }
            catch (Exception ex)
            {
                throw new VeyronException("Failed to retrieve data.", ex);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the list of objects found in the directory.
        /// </summary>
        /// <param name="context">The data provider context.</param>
        /// <returns>The list of objects found in the directory.</returns>
        public IList<ProviderItem> GetData(DataProviderContext context)
        {
            var systemOptions = LoadSystemOptions();

            var ldapDirectory = systemOptions.LdapProfiles.FirstOrDefault(x => x.Id == LdapProfileId);
            if (ldapDirectory == null)
                throw new DirectoryNotFoundException("Cannot find LDAP directory associated with ESync.");

            var username = !string.IsNullOrEmpty(ldapDirectory.Username) ? ldapDirectory.Username : null;
            var password = !string.IsNullOrEmpty(username) ? ldapDirectory.Password : null;

            using (var directoryEntry = DirectoryServicesFactory.CreateDirectoryEntry(ldapDirectory.ServerPath, username, password, ldapDirectory.RootPath, ldapDirectory.UseSSL))
            {
                using (var directorySearcher = DirectoryServicesFactory.CreateDirectorySearcher(directoryEntry, Filter))
                {
                    var attributesToLoad = AttributesToLoad.Distinct(StringComparer.OrdinalIgnoreCase).Where(CanUseAttribute).ToArray();

                    directorySearcher.PropertiesToLoad.AddRange(attributesToLoad);

                    using (var searchResultCollection = directorySearcher.FindAll())
                    {
                        var result = new List<ProviderItem>();

                        foreach (SearchResult searchResult in searchResultCollection)
                        {
                            var item = new ProviderItem();

                            foreach (var attributeName in attributesToLoad)
                            {
                                if (!searchResult.Properties.Contains(attributeName))
                                    continue;

                                var valueCollection = searchResult.Properties[attributeName];

                                item.Fields.Add(new ProviderFieldValue(-1, attributeName, GetAttributeValue(valueCollection)));
                            }

                            result.Add(item);
                        }

                        return result;
                    }
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Gets the data.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>IList{ProviderItem}.</returns>
 public abstract IList<ProviderItem> GetData(DataProviderContext context);