Пример #1
0
        private void UpdateIcons()
        {
            for (int i = 0, n = source_model.IterNChildren(); i < n; i++)
            {
                TreeIter iter;
                if (source_model.IterNthChild(out iter, i))
                {
                    object        o      = source_model.GetValue(iter, 0);
                    IImportSource source = (IImportSource)source_model.GetValue(iter, 2);
                    if (o != null)
                    {
                        ((Gdk.Pixbuf)o).Dispose();
                    }

                    if (source != null)
                    {
                        var icon = GetIcon(source);
                        if (icon != null)
                        {
                            source_model.SetValue(iter, 0, icon);
                        }
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the ImportConsumerBase class
 /// </summary>
 /// <param name="source">the importsource that is providing data for this consumer</param>
 /// <param name="virtualColumns">a set of columns that is evaluated on does not directly result from the provided Data</param>
 protected ImportConsumerBase(IImportSource <T, TNotification> source, ConstConfigurationCollection virtualColumns)
 {
     VirtualColumns        = virtualColumns;
     AcceptanceConstraints = new SimpleDecider <T>(false);
     this.source           = source;
     source.Register(this);
 }
Пример #3
0
 public Importer(IImportSource importSource,
                 IParser[] parsers,
                 IMediator mediator)
 {
     _importSource = importSource;
     _parsers      = parsers;
     _mediator     = mediator;
 }
Пример #4
0
 static void DeactivateSource(IImportSource source)
 {
     if (source == null)
     {
         return;
     }
     source.Deactivate();
 }
Пример #5
0
        private TreeIter AddSource(IImportSource source)
        {
            if (source == null)
            {
                return(TreeIter.Zero);
            }

            return(source_model.AppendValues(GetIcon(source), source.Name, source));
        }
Пример #6
0
        private void UpdateActions(bool force)
        {
            Source source = ActionSource;

            if ((force || source != last_source) && source != null)
            {
                IUnmapableSource    unmapable      = (source as IUnmapableSource);
                IImportSource       import_source  = (source as IImportSource);
                SmartPlaylistSource smart_playlist = (source as SmartPlaylistSource);
                PrimarySource       primary_source = (source as PrimarySource) ?? (source.Parent as PrimarySource);

                UpdateAction("UnmapSourceAction", unmapable != null, unmapable != null && unmapable.CanUnmap, source);
                UpdateAction("RenameSourceAction", source.CanRename, true, null);
                UpdateAction("ImportSourceAction", import_source != null, import_source != null && import_source.CanImport, source);
                UpdateAction("ExportPlaylistAction", source is AbstractPlaylistSource, true, source);
                UpdateAction("SourcePropertiesAction", source.HasProperties, true, source);
                UpdateAction("SourcePreferencesAction", source.PreferencesPageId != null, true, source);
                UpdateAction("RefreshSmartPlaylistAction", smart_playlist != null && smart_playlist.CanRefresh, true, source);
                this["OpenSourceSwitcher"].Visible = false;

                bool playlists_writable = primary_source != null && primary_source.SupportsPlaylists && !primary_source.PlaylistsReadOnly;
                UpdateAction("NewPlaylistAction", playlists_writable, true, source);
                UpdateAction("NewSmartPlaylistAction", playlists_writable, true, source);

                /*UpdateAction ("NewSmartPlaylistFromSearchAction", (source is LibrarySource || source.Parent is LibrarySource),
                 *      !String.IsNullOrEmpty (source.FilterQuery), source);*/

                ActionGroup browser_actions = Actions.FindActionGroup("BrowserView");
                if (browser_actions != null)
                {
                    IFilterableSource filterable_source = source as IFilterableSource;
                    bool has_browser = filterable_source != null && filterable_source.AvailableFilters.Count > 0;
                    UpdateAction(browser_actions["BrowserTopAction"], has_browser);
                    UpdateAction(browser_actions["BrowserLeftAction"], has_browser);
                    UpdateAction(browser_actions["BrowserVisibleAction"], has_browser);
                }

                last_source = source;
            }

            if (source != null)
            {
                UpdateAction("SortChildrenAction", source.ChildSortTypes.Length > 0 && source.Children.Count > 1, true, source);
            }

            Action <Source> handler = Updated;

            if (handler != null)
            {
                handler(source);
            }
        }
Пример #7
0
        public void SwitchToFolderSource(SafeUri uri)
        {
            IImportSource source = null;

            if (!history_sources.TryGetValue(uri, out source))
            {
                var name = uri.GetFilename();
                source = new FileImportSource(uri, name, "folder");
                history_sources[uri] = source;
            }

            PopulateSourceCombo(source);
            Controller.ActiveSource = source;
        }
Пример #8
0
        void DoScan(IImportSource source, bool recurse, bool merge, CancellationToken token)
        {
            FireEvent(ImportEvent.PhotoScanStarted);

            foreach (var info in source.ScanPhotos(recurse, merge))
            {
                ThreadAssist.ProxyToMain(() => Photos.Add(info));
                if (token.IsCancellationRequested)
                {
                    break;
                }
            }

            FireEvent(ImportEvent.PhotoScanFinished);
        }
Пример #9
0
        public ImportModel(int dossierId, string pathFile, string pathFilesTmp)
        {
            _dossierId = dossierId;
            IImportSource importSource = new ImportFromTxtFile(pathFile, pathFilesTmp, dossierId);

            _ImportSource    = importSource;
            _importRecordTmp = _ImportSource.GetRecordTmp();
            _pathFilesTmp    = pathFilesTmp;


            _Report.totalRecordsProcessed = _ImportSource.TotalRecordsProcessed;
            _Report.FailedImports         = _ImportSource.FailedImports;
            _Report.SuccessfulImports     = _ImportSource.TotalRecordsProcessed - _ImportSource.FailedImports;
            _Report.dossierId             = dossierId;
        }
Пример #10
0
        private bool FindSourceIter(out TreeIter iter, IImportSource source)
        {
            iter = TreeIter.Zero;

            for (int i = 0, n = source_model.IterNChildren(); i < n; i++)
            {
                TreeIter _iter;
                if (source_model.IterNthChild(out _iter, i))
                {
                    if (source == source_model.GetValue(_iter, 2))
                    {
                        iter = _iter;
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #11
0
        private static void RegisterInstance(string filePath)
        {
            _importSource = new ImportFileSource();

            _builder = new InputBuilder(_importSource);

            var gameSetting =
                _builder
                .ReadText(filePath)
                .ReadBoardSize()
                .ReadExitPoint()
                .ReadMinePosition()
                .ReadStartingPosition()
                .ReadSequences()
                .Build();

            _handleSequenceMove = new SequenceMoveHandler(gameSetting);

            _processSequence = new SequenceProcessor(gameSetting, _handleSequenceMove);
        }
Пример #12
0
        void PopulateSourceCombo(IImportSource sourceToActivate)
        {
            int activate_index = 0;

            sources_combo.Changed -= OnSourceComboChanged;
            Sources.Clear();
            Sources.AppendValues(null, Catalog.GetString("Choose Import source..."), String.Empty, true);
            Sources.AppendValues(null, select_folder_label, "folder", true);
            Sources.AppendValues(null, String.Empty, String.Empty);
            bool mount_added = false;

            foreach (var source in Controller.Sources)
            {
                if (source == sourceToActivate)
                {
                    activate_index = Sources.IterNChildren();
                }
                Sources.AppendValues(source, source.Name, source.IconName, true);
                mount_added = true;
            }
            if (!mount_added)
            {
                Sources.AppendValues(null, Catalog.GetString("(No Cameras Detected)"), String.Empty, false);
            }

            if (history_sources.Count > 0)
            {
                Sources.AppendValues(null, String.Empty, String.Empty);
                foreach (var source in history_sources.Values)
                {
                    if (source == sourceToActivate)
                    {
                        activate_index = Sources.IterNChildren();
                    }
                    Sources.AppendValues(source, source.Name, source.IconName, true);
                }
            }
            sources_combo.Changed += OnSourceComboChanged;
            sources_combo.Active   = activate_index;
        }
Пример #13
0
 protected DictionaryConsumerBase(IImportSource <IDictionary <string, TValue>, DictionaryAcceptanceCallbackParameter <TValue> > source, ConstConfigurationCollection virtualColumns) : base(source, virtualColumns)
 {
 }
Пример #14
0
 public InputBuilder(IImportSource importSource)
 {
     _importSource = importSource;
     _gameSetting  = new GameSetting();
 }
Пример #15
0
 void DeactivateSource(IImportSource source)
 {
     if (source == null)
         return;
     source.Deactivate ();
 }
Пример #16
0
 public Import([CanBeNull] IImportSource importSource)
 {
     ImportSource = importSource;
 }
Пример #17
0
		void PopulateSourceCombo (IImportSource sourceToActivate)
		{
			int activate_index = 0;
			sources_combo.Changed -= OnSourceComboChanged;
			Sources.Clear ();
			Sources.AppendValues (null, Catalog.GetString ("Choose Import source..."), String.Empty, true);
			Sources.AppendValues (null, select_folder_label, "folder", true);
			Sources.AppendValues (null, String.Empty, String.Empty);
			bool mount_added = false;
			foreach (var source in Controller.Sources) {
				if (source == sourceToActivate) {
					activate_index = Sources.IterNChildren ();
				}
				Sources.AppendValues (source, source.Name, source.IconName, true);
				mount_added = true;
			}
			if (!mount_added) {
				Sources.AppendValues (null, Catalog.GetString ("(No Cameras Detected)"), String.Empty, false);
			}

			if (history_sources.Count > 0) {
				Sources.AppendValues (null, String.Empty, String.Empty);
				foreach (var source in history_sources.Values) {
					if (source == sourceToActivate) {
						activate_index = Sources.IterNChildren ();
					}
					Sources.AppendValues (source, source.Name, source.IconName, true);
				}
			}
			sources_combo.Changed += OnSourceComboChanged;
			sources_combo.Active = activate_index;
		}
 protected KeyValueConsumerBase(IImportSource <IBasicKeyValueProvider, KeyValueAcceptanceCallbackParameter> source, ConstConfigurationCollection virtualColumns) : base(source, virtualColumns)
 {
 }
Пример #19
0
        public ImportResult Import(Core.Import import, IImportSource source, bool save)
        {
            var result = new ImportResult
            {
                Date = DateTime.UtcNow,
                File = import.Location,
                Type = import.Type.ToString()
            };

            try
            {
                // build columns
                result.Step = ImportStep.BuildLayout;
                var layout = import.Columns.Select(x =>
                                                   String.IsNullOrEmpty(x.Target)
                            ? (TEnum)Enum.Parse(typeof(TEnum), "None")
                            : (TEnum)Enum.Parse(typeof(TEnum), x.Target)
                                                   ).ToArray();
                result.Layout = layout.Select(x => x.ToString()).ToArray();

                // get data types
                var types = layout.Select(x => GetColumnType(x)).ToArray();

                // validate layout
                result.Step = ImportStep.ValidateLayout;
                var layoutValid = ValidateLayout(layout);
                if (!layoutValid.Success)
                {
                    layoutValid.Problems.Each(x => result.AddProblem(x));
                    return(result);
                }

                // convert all row data
                result.Step = ImportStep.ConvertRowData;
                var rows = source.Select(data => new ImportRow(data, types, layout)).ToList();
                if (rows.Any(x => !x.IsValid))
                {
                    FillRowResults(result, rows);
                    result.AddProblem("Some data could not be converted to the correct format. See row-by-row results for specific problems.");
                    return(result);
                }

                // find existing rows
                result.Step = ImportStep.FindRowEntities;
                Parallel.ForEach(rows, r => r.Entity = Find(r));

                // create missing rows
                result.Step = ImportStep.CreateRowEntities;
                Parallel.ForEach(
                    rows.Where(x => null == x.Entity),
                    r => {
                    r.Entity = Create(r);
                    r.IsNew  = true;
                });

                // validate all row data
                result.Step = ImportStep.ValidateRows;
                foreach (var r in rows)
                {
                    ValidateRow(r);
                }

                // apply all row values
                result.Step = ImportStep.ImportRows;
                Parallel.ForEach(rows, r => Apply(r.Entity, r));
                if (rows.Any(x => !x.IsValid))
                {
                    FillRowResults(result, rows);
                    result.AddProblem("Some data could not be imported into the system. See row-by-row results for specific problems.");
                    return(result);
                }

                // save all records
                if (save)
                {
                    result.Step = ImportStep.SaveRows;
                    Parallel.ForEach(rows, r =>
                    {
                        try
                        {
                            Save(r.Entity);
                        }
                        catch (CouchException ex)
                        {
                            if (ex.Status == (int)HttpStatusCode.Conflict)
                            {
                                // conflicts typically occur when a unique id is supplied for two or more
                                // new rows in an import sheet.. i.e. product id 1234 appears twice, and is new
                                r.AddProblem(
                                    @"There was a conflict saving this record, typically because a unique was duplicated in the spreadsheet.");
                            }
                            else
                            {
                                throw;
                            }
                        }
                    });
                }

                Completed();

                FillRowResults(result, rows);
                result.Step    = ImportStep.Complete;
                result.Success = true;
            }
            catch (Exception ex)
            {
                result.AddProblem(String.Format("ERROR: Import encountered an unexpected error, proces aborted.<br/>Error: {0}<br />Stack: {1}.", (ex.InnerException ?? ex).Message, (ex.InnerException ?? ex).StackTrace));
                if (result.Step == ImportStep.SaveRows)
                {
                    result.AddProblem("DANGER: An error occurred DURING the Save step, meaning that some rows may have been written to the database, and some not. Re-importing this sheet could cause duplication of data.");
                }
            }
            return(result);
        }
Пример #20
0
 private Gdk.Pixbuf GetIcon(IImportSource source)
 {
     return(IconThemeUtils.LoadIcon(22, source.IconNames));
 }
Пример #21
0
 public InputBuilderTests()
 {
     _importSource = Substitute.For <IImportSource>();
     _inputBuilder = new InputBuilder(_importSource);
 }
Пример #22
0
 /// <summary>
 /// Initializes a new instance of the ImportConsumerBase class
 /// </summary>
 /// <param name="source">the importsource that is providing data for this consumer</param>
 protected ImportConsumerBase(IImportSource <T, TNotification> source) : this(source, new ConstConfigurationCollection())
 {
 }