public void Remove(string key)
 {
     if (ContextItems.Contains(key))
     {
         ContextItems.Remove(key);
     }
 }
Example #2
0
        /// <summary>
        /// Reads all settings from the hidden storage worksheet
        /// </summary>
        protected void ReadFromWorksheet()
        {
            if (Workbook == null)
            {
                Logger.Warn("ReadFromWorksheet: No workbook; exiting...");
            }

            _contexts.Clear();
            Range r = StoreSheet.UsedRange;

            // The first row on a storage worksheet is reserved for internal
            // use (e.g., flags).
            Item         item;
            ContextItems context;

            Logger.Info("ReadFromWorksheet: Reading rows...");
            for (int row = FIRSTROW; row <= r.Rows.Count; row++)
            {
                item = new Item(_storeSheet, row);
                Logger.Info("ReadFromWorksheet: ... {0}::{1}", item.Context, item.Key);
                if (_contexts.ContainsKey(item.Context))
                {
                    context = _contexts[item.Context];
                }
                else
                {
                    context = new ContextItems();
                    _contexts.Add(item.Context, context);
                };
                context.Add(item.Key, item);
            }
        }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Loaded     += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            ContCommand = new RelayCommand <object>((o) =>
            {
            });

            RightCommand = new RelayCommand <object>((o) =>
            {
                ContextItems.Clear();
                string itemClicked = (string)o;
                ContextItems.Add(new Context()
                {
                    Name = "Foo " + itemClicked, Enabled = false, guid = Guid.NewGuid()
                });
                ContextItems.Add(new Context()
                {
                    Name = "Bar " + itemClicked, Enabled = false, guid = Guid.NewGuid()
                });
                ContextItems.Add(new Context()
                {
                    Name = "Hello", Enabled = false, guid = Guid.NewGuid()
                });
            });
        }
Example #4
0
        private async Task RefreshContextAsync(TemplateViewModel selection)
        {
            if (!await EnsureCookiecutterIsInstalled())
            {
                return;
            }

            try {
                IsLoading        = true;
                IsLoadingSuccess = false;
                IsLoadingError   = false;

                var result = await _cutterClient.LoadContextAsync(selection.ClonedPath, UserConfigFilePath);

                ContextItems.Clear();
                foreach (var item in result.Item1)
                {
                    ContextItems.Add(new ContextItemViewModel(item.Name, item.DefaultValue, item.Values));
                }

                IsLoading        = false;
                IsLoadingSuccess = true;
                IsLoadingError   = false;

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateSuccess, selection.DisplayName));
                _outputWindow.ShowAndActivate();

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection);

                // Go to the context page
                ContextLoaded?.Invoke(this, EventArgs.Empty);
            } catch (InvalidOperationException ex) {
                IsLoading        = false;
                IsLoadingSuccess = false;
                IsLoadingError   = true;

                _outputWindow.WriteErrorLine(ex.Message);

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateFailed, selection.DisplayName));
                _outputWindow.ShowAndActivate();

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            } catch (ProcessException ex) {
                IsLoading        = false;
                IsLoadingSuccess = false;
                IsLoadingError   = true;

                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.ProcessExitCodeMessage, ex.Result.ExeFileName, ex.Result.ExitCode));
                _outputWindow.WriteLine(string.Join(Environment.NewLine, ex.Result.StandardOutputLines));
                _outputWindow.WriteErrorLine(string.Join(Environment.NewLine, ex.Result.StandardErrorLines));

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateFailed, selection.DisplayName));
                _outputWindow.ShowAndActivate();

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            }
        }
Example #5
0
 /// <summary>
 ///   Sets current (auto) IDbTransaction for a connection.</summary>
 /// <param name="connection">
 ///   Connection (required).</param>
 /// <param name="transaction">
 ///   Default (auto) transaction for the connection.</param>
 internal static void SetDefaultTransaction(IDbConnection connection, IDbTransaction transaction)
 {
     if (connection == null)
     {
         return;
     }
     ContextItems.Set(connection, transaction);
 }
Example #6
0
        protected override void RemoveEntry(string key)
        {
            if (HasContextItems == false)
            {
                return;
            }

            ContextItems.Remove(key);
        }
Example #7
0
        /// <summary>
        ///   Gets current IDbTransaction for a connection, that is started with DataHelper.BeginTransaction method.</summary>
        /// <param name="connection">
        ///   Connection (required)</param>
        /// <returns>
        ///   The automatic transaction associated with the connection.</returns>
        private static IDbTransaction GetDefaultTransaction(IDbConnection connection)
        {
            if (connection == null)
            {
                return(null);
            }

            return(ContextItems.Get(connection) as IDbTransaction);
        }
        protected override IEnumerable<DictionaryEntry> GetDictionaryEntries()
        {
            const string prefix = CacheItemPrefix + "-";

            if (HasContextItems == false) return Enumerable.Empty<DictionaryEntry>();

            return ContextItems.Cast<DictionaryEntry>()
                .Where(x => x.Key is string && ((string)x.Key).StartsWith(prefix));
        }
		public void AddItemToCallContext()
		{
			ContextItems item = new ContextItems();
			item.SetContextItem("AppVersion", "1234");

			Hashtable hash = (Hashtable)CallContext.GetData(ContextItems.CallContextSlotName);
			Assert.IsNotNull(hash);
			Assert.AreEqual(1, hash.Count);
			Assert.AreEqual("1234", hash["AppVersion"]);
		}
Example #10
0
        public void Reset()
        {
            ContextItems.Clear();

            ResetStatus();

            _templateLocalFolderPath = null;

            HomeClicked?.Invoke(this, EventArgs.Empty);
        }
        public string GetSomething()
        {
            var contextItem = ContextItems.ItemByName("HelloWorldObject");

            if (contextItem.Type == typeof(string))
            {
                return(string.Format("My sample plug-in returns - {0}", (string)contextItem.Value));
            }

            return(null);
        }
        public void AddItemToCallContext()
        {
            ContextItems item = new ContextItems();

            item.SetContextItem("AppVersion", "1234");
            Hashtable hash = (Hashtable)CallContext.GetData(ContextItems.CallContextSlotName);

            Assert.IsNotNull(hash);
            Assert.AreEqual(1, hash.Count);
            Assert.AreEqual("1234", hash["AppVersion"]);
        }
Example #13
0
        public async Task CreateFilesAsync()
        {
            var selection = SelectedTemplate;

            Debug.Assert(selection != null);
            if (selection == null)
            {
                throw new InvalidOperationException("CreateFilesAsync called with null SelectedTemplate");
            }

            ResetStatus();

            CreatingStatus           = OperationStatus.InProgress;
            OpenInExplorerFolderPath = null;

            try {
                var contextFilePath = Path.GetTempFileName();
                SaveUserInput(contextFilePath);

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(String.Empty);
                _outputWindow.WriteLine(Strings.RunningTemplateStarted.FormatUI(selection.DisplayName));

                await _cutterClient.GenerateProjectAsync(_templateLocalFolderPath, UserConfigFilePath, contextFilePath, OutputFolderPath);

                try {
                    File.Delete(contextFilePath);
                } catch (UnauthorizedAccessException) {
                } catch (IOException) {
                }

                _outputWindow.WriteLine(Strings.RunningTemplateSuccess.FormatUI(selection.DisplayName, OutputFolderPath));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Run, selection);

                ContextItems.Clear();
                ResetStatus();
                _templateLocalFolderPath = null;
                OpenInExplorerFolderPath = OutputFolderPath;
                CreatingStatus           = OperationStatus.Succeeded;

                Home();
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                CreatingStatus = OperationStatus.Failed;

                _outputWindow.WriteErrorLine(ex.Message);
                _outputWindow.WriteLine(Strings.RunningTemplateFailed.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Run, selection, ex);
            }
        }
        /// <summary>
        /// 获取指定数据库对应的当前最内部的 <see cref="LocalTransactionBlock"/>。
        /// </summary>
        /// <param name="dbSetting">The database setting.</param>
        /// <returns></returns>
        public static LocalTransactionBlock GetCurrentTransactionBlock(DbSetting dbSetting)
        {
            var currentScopeItemKey = ContextCurrentScopeKey(dbSetting.Database);

            object res = null;

            if (ContextItems.TryGetValue(currentScopeItemKey, out res))
            {
                return(res as LocalTransactionBlock);
            }

            return(null);
        }
        private static void SetCurrentTransactionBlock(DbSetting dbSetting, LocalTransactionBlock value)
        {
            var currentScopeItemKey = ContextCurrentScopeKey(dbSetting.Database);

            if (value == null)
            {
                ContextItems.Remove(currentScopeItemKey);
            }
            else
            {
                ContextItems[currentScopeItemKey] = value;
            }
        }
		public void FlushItemsFromCallContext()
		{
			ContextItems item = new ContextItems();
			item.SetContextItem("AppVersion", "1234");

			Hashtable hash = (Hashtable)CallContext.GetData(ContextItems.CallContextSlotName);
			Assert.IsNotNull(hash);
			Assert.AreEqual(1, hash.Count);

			item.FlushContextItems();
			Hashtable hash2 = (Hashtable)CallContext.GetData(ContextItems.CallContextSlotName);
			Assert.IsNull(hash2);
		}
        public void FlushItemsFromCallContext()
        {
            ContextItems item = new ContextItems();

            item.SetContextItem("AppVersion", "1234");
            Hashtable hash = (Hashtable)CallContext.GetData(ContextItems.CallContextSlotName);

            Assert.IsNotNull(hash);
            Assert.AreEqual(1, hash.Count);
            item.FlushContextItems();
            Hashtable hash2 = (Hashtable)CallContext.GetData(ContextItems.CallContextSlotName);

            Assert.IsNull(hash2);
        }
Example #18
0
        public override bool OnContextItemSelected(IMenuItem item)
        {
            ContextItems selected = (ContextItems)item.ItemId;

            switch (selected)
            {
            case ContextItems.Delete:
                selectedMap.DeleteFiles();
                ListView listView = (ListView)FindViewById(Android.Resource.Id.List);
                ((MapsAdapter)listView.Adapter).NotifyDataSetChanged();
                break;

            default:
                return(base.OnOptionsItemSelected(item));
            }
            return(true);
        }
        // Loads all sample plugins created before yesterday from specified directory
        public IEnumerable<ISamplePlugin> LoadAllSamplePluginsWithin(string directory)
        {
            // Create directory info instance from directory path
            var path = new DirectoryInfo(directory);

            // Create a context item collection
            ICollection<IContextItem> contextItems = new ContextItems();

            // Add some context objects
            contextItems.Add(new ContextItem("HelloWorldObject", "Hello World !!!"));

            // Enumerate through all plugins with attribute info that match an example predicate
            foreach (var plugin in new Plugins<ISamplePlugin>(path, x => x.DateCreated > DateTime.Now))
            {
                // Yield return instance of enumerable plugin with injected context
                yield return plugin.GetInitialisedPlugin((IContextItems)contextItems);
            }
        }
Example #20
0
        // Loads all sample plugins created before yesterday from specified directory
        public IEnumerable <ISamplePlugin> LoadAllSamplePluginsWithin(string directory)
        {
            // Create directory info instance from directory path
            var path = new DirectoryInfo(directory);

            // Create a context item collection
            ICollection <IContextItem> contextItems = new ContextItems();

            // Add some context objects
            contextItems.Add(new ContextItem("HelloWorldObject", "Hello World !!!"));

            // Enumerate through all plugins with attribute info that match an example predicate
            foreach (var plugin in new Plugins <ISamplePlugin>(path, x => x.DateCreated > DateTime.Now))
            {
                // Yield return instance of enumerable plugin with injected context
                yield return(plugin.GetInitialisedPlugin((IContextItems)contextItems));
            }
        }
Example #21
0
        public void Should_not_output_session_id_in_details_if_no_cookie_or_id_in_request()
        {
            ContextItems.Clear();

            var request = _requestBuilder.AddSession()
                          .AddMessage(_standardTestMessage)
                          .Build();

            Target.Process(HttpContext, request);

            WaitForEvent();

            var loggedMessage = _eventArgs.Messages.FirstOrDefault();

            Assert.That(loggedMessage, Is.Not.Null);

            Assert.That(loggedMessage.Details, Does.Not.Contain("<SessionId>"));
        }
Example #22
0
        public void Reset() {
            ContextItems.Clear();

            IsCloning = false;
            IsCloningSuccess = false;
            IsCloningError = false;

            IsLoading = false;
            IsLoadingSuccess = false;
            IsLoadingError = false;

            IsCreating = false;
            IsCreatingSuccess = false;
            IsCreatingError = false;

            _templateLocalFolderPath = null;

            HomeClicked?.Invoke(this, EventArgs.Empty);
        }
Example #23
0
        private async Task RefreshContextAsync(TemplateViewModel selection)
        {
            if (!await EnsureCookiecutterIsInstalledAsync())
            {
                return;
            }

            try {
                LoadingStatus = OperationStatus.InProgress;

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(Strings.LoadingTemplateStarted.FormatUI(selection.DisplayName));

                var unrenderedContext = await _cutterClient.LoadUnrenderedContextAsync(selection.ClonedPath, UserConfigFilePath);

                ContextItems.Clear();
                foreach (var item in unrenderedContext.Items.Where(it => !it.Name.StartsWith("_", StringComparison.InvariantCulture)))
                {
                    ContextItems.Add(new ContextItemViewModel(item.Name, item.Selector, item.Label, item.Description, item.Url, item.DefaultValue, item.Values));
                }

                HasPostCommands           = unrenderedContext.Commands.Count > 0;
                ShouldExecutePostCommands = HasPostCommands;

                LoadingStatus = OperationStatus.Succeeded;

                _outputWindow.WriteLine(Strings.LoadingTemplateSuccess.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection);

                // Go to the context page
                ContextLoaded?.Invoke(this, EventArgs.Empty);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                LoadingStatus = OperationStatus.Failed;

                _outputWindow.WriteErrorLine(ex.Message);
                _outputWindow.WriteLine(Strings.LoadingTemplateFailed.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            }
        }
Example #24
0
        private async Task RefreshContextAsync(TemplateViewModel selection)
        {
            if (!await EnsureCookiecutterIsInstalled())
            {
                return;
            }

            try {
                LoadingStatus = OperationStatus.InProgress;

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(Strings.LoadingTemplateStarted.FormatUI(selection.DisplayName));

                var result = await _cutterClient.LoadContextAsync(selection.ClonedPath, UserConfigFilePath);

                ContextItems.Clear();
                foreach (var item in result)
                {
                    ContextItems.Add(new ContextItemViewModel(item.Name, item.DefaultValue, item.Values));
                }

                LoadingStatus = OperationStatus.Succeeded;

                _outputWindow.WriteLine(Strings.LoadingTemplateSuccess.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection);

                // Go to the context page
                ContextLoaded?.Invoke(this, EventArgs.Empty);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                LoadingStatus = OperationStatus.Failed;

                _outputWindow.WriteErrorLine(ex.Message);
                _outputWindow.WriteLine(Strings.LoadingTemplateFailed.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            }
        }
Example #25
0
        public async Task CreateFilesAsync()
        {
            var selection = SelectedTemplate;

            Debug.Assert(selection != null);
            if (selection == null)
            {
                throw new InvalidOperationException("CreateFilesAsync called with null SelectedTemplate");
            }

            ResetStatus();

            CreatingStatus           = OperationStatus.InProgress;
            OpenInExplorerFolderPath = null;

            try {
                var contextFilePath = Path.GetTempFileName();
                SaveUserInput(contextFilePath);

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(String.Empty);
                _outputWindow.WriteLine(Strings.RunningTemplateStarted.FormatUI(selection.DisplayName));

                var operationResult = await _cutterClient.CreateFilesAsync(_templateLocalFolderPath, UserConfigFilePath, contextFilePath, OutputFolderPath);

                if (operationResult.FilesReplaced.Length > 0)
                {
                    _outputWindow.WriteLine(Strings.ReplacedFilesHeader);
                    foreach (var replacedfile in operationResult.FilesReplaced)
                    {
                        _outputWindow.WriteLine(Strings.ReplacedFile.FormatUI(replacedfile.OriginalFilePath, replacedfile.BackupFilePath));
                    }
                }

                var renderedContext = await _cutterClient.LoadRenderedContextAsync(_templateLocalFolderPath, UserConfigFilePath, contextFilePath, OutputFolderPath);

                _postCommands = renderedContext.Commands.ToArray();

                try {
                    File.Delete(contextFilePath);
                } catch (UnauthorizedAccessException) {
                } catch (IOException) {
                }

                if (TargetProjectLocation != null)
                {
                    try {
                        var location = new ProjectLocation()
                        {
                            FolderPath        = OutputFolderPath,
                            ProjectUniqueName = TargetProjectLocation.ProjectUniqueName,
                        };
                        _projectSystemClient.AddToProject(location, operationResult);

                        RunPostCommands();

                        ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.AddToProject, selection);
                    } catch (Exception ex) when(!ex.IsCriticalException())
                    {
                        _outputWindow.WriteErrorLine(Strings.AddToProjectError.FormatUI(ex.Message));

                        ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.AddToProject, selection, ex);
                    }
                }

                _outputWindow.WriteLine(Strings.RunningTemplateSuccess.FormatUI(selection.DisplayName, OutputFolderPath));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Run, selection);

                ContextItems.Clear();
                ResetStatus();
                _templateLocalFolderPath = null;
                OpenInExplorerFolderPath = OutputFolderPath;
                CreatingStatus           = OperationStatus.Succeeded;

                if (TargetProjectLocation != null)
                {
                    // Don't show the succeeded message and open in solution explorer link when adding to project
                    CreatingStatus = OperationStatus.NotStarted;
                }

                Home();
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                CreatingStatus = OperationStatus.Failed;

                _outputWindow.WriteErrorLine(ex.Message);
                _outputWindow.WriteLine(Strings.RunningTemplateFailed.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Run, selection, ex);
            }
        }
Example #26
0
 private void MainViewModel_StackPushed()
 {
     ContextItems.Reset(_selectedIndexables.Select(x => x.Name));
 }
Example #27
0
 public void Login(string username)
 {
     Username = username;
     ContextItems.Remove("CurrentUser");
 }