Esempio n. 1
0
        //generate the navbar after all the pages are added to the site.
        //the navbar is generated per page because the active item is different for each page.
        //can only handle navs with dropdowns one level deep.
        //TODO: Add active item highlight to dropdown pages?
        public void GenerateNav()
        {
            DataElement output = new DataElement("nav.html"); //create the unpopulated navbar

            foreach (NavItem i in ParentSite.NavItems)        //iterate through the navitems list populated when adding pages to the site
            {
                DataElement item;                             //the html element for a particular page or dropdown category
                if (TemplateElement.Id == i.title)
                {
                    item = new DataElement("navItemActive.html");
                }
                else if (i.children.Count > 0)                 //if the item has children, it is a dropdown category rather than a page.
                {
                    item = new DataElement("dropUp.html");
                    foreach (NavItem c in i.children)                     //populate the category with its pages
                    {
                        DataElement child = new DataElement("dropDownItem.html");
                        child.AppendToProperty("#TITLE#", new LiteralElement(c.title));
                        child.AppendToProperty("#HREF#", new LiteralElement(GenerateRelativeURL(c.LinkedPage)));
                        item.AppendToProperty("#CHILDREN#", child);
                    }
                }
                else
                {
                    item = new DataElement("navItem.html");
                }
                item.AppendToProperty("#TITLE#", new LiteralElement(i.title));
                item.AppendToProperty("#HREF#", new LiteralElement(GenerateRelativeURL(i.LinkedPage)));
                output.AppendToProperty("#CHILDREN#", item);               //append the item to the navbar
            }
            TemplateElement.AppendToProperty("#NAV#", output);             //bake the navbar DataElement into html to replace the #NAV# macro or property or whatever with.
        }
Esempio n. 2
0
        void Event_CreateRow(object sender, RoutedEventArgs e)
        {
            control = new NewWriterTemplateControl()
            {
                DataContext = Model, Title = "New Template Row", ResizeMode = ResizeMode.CanResizeWithGrip,
            };
            TemplateElement element = null;
            var             rc      = new RelayCommand((x) => {
                control.DialogResult = true;
                element = new TemplateElement()
                {
                    Title = control.tbName.Text, Table = control.cbGroup.Text
                };
                control.Close();
            });

            control.Buttons = new[] { control.CancelButton, new Button()
                                      {
                                          Content = "okay", Command = rc, IsDefault = true
                                      } };
            //			control.cbGroup.ItemsSource = model.GroupNames;
            var value = control.ShowDialog();

            if (!(value.HasValue && value.Value))
            {
                return;
            }
            //			ModernDialog.ShowMessage("We have our template-element","Success",MessageBoxButton.OK);
            var fname = Ofd.FileName;

            Model.util.InsertRow(Ofd.FileName, element);
            InitializeData();
            cbTplGroup.Text = element.Table;
            cbTplName.Text  = element.Title;
        }
Esempio n. 3
0
        public Page(Site site, string title, string contentPath = null, string subDirectory = null, string altTemplatePath = null)
        {
            ParentSite   = site;
            Title        = title;
            SubDirectory = subDirectory;

            if (SubDirectory != null && SubDirectory != "" && !Directory.Exists(SubDirectory))
            {
                Directory.CreateDirectory(site.RootDir + SubDirectory);
            }

            if (altTemplatePath != null)
            {
                TemplateElement = new DataElement(altTemplatePath, title);
            }
            else
            {
                TemplateElement = new DataElement(ParentSite.TemplatePath, title);
            }

            TemplateElement.AppendToProperty("#TITLE#", new LiteralElement(title + " - " + ParentSite.Sitename));             //page title
            if (contentPath != null)
            {
                ContentElement = new DataElement(contentPath);
            }
        }
Esempio n. 4
0
            protected override object GetElementKey(ConfigurationElement element)
            {
                TemplateElement template = element as TemplateElement;

                if (template == null)
                {
                    throw new InvalidOperationException(string.Format("Cannot derive key for element: {0}", element.GetType().FullName));
                }
                return(template.Output);
            }
Esempio n. 5
0
        public void SetHeaders()
        {
            xmlNodeList HeadersList = TemplateElement.SelectNodes("HeadersList");

            foreach (xmlElement Header in HeadersList)
            {
                string HeaderName  = Header.GetAttribute("Name");
                string HeaderXq    = Header.GetAttribute("Value");
                string HeaderValue = SourceXmlDocument.Root.XQuery(HeaderXq);
                httpClient.DefaultRequestHeaders.Add(HeaderName, HeaderValue);
            }
        }
Esempio n. 6
0
 protected override void VisitTemplateElement(TemplateElement templateElement)
 {
     using (StartNodeObject(templateElement))
     {
         _writer.Member("value");
         _writer.StartObject();
         Member("raw", templateElement.Value.Raw);
         Member("cooked", templateElement.Value.Cooked);
         _writer.EndObject();
         Member("tail", templateElement.Tail);
     }
 }
Esempio n. 7
0
        private void RenderFields([NotNull] XElement templateElement)
        {
            Debug.ArgumentNotNull(templateElement, nameof(templateElement));

            FieldsListView.Items.Clear();

            foreach (var sectionElement in templateElement.Elements())
            {
                var section = new TemplateElement
                {
                    Name    = sectionElement.GetAttributeValue("name"),
                    Type    = string.Empty,
                    ItemUri = new ItemUri(TemplateUri.DatabaseUri, new ItemId(new Guid(sectionElement.GetAttributeValue("id")))),
                    Icon    = new Icon(TemplateUri.Site, sectionElement.GetAttributeValue("icon"))
                };

                FieldsListView.Items.Add(section);

                foreach (var fieldElement in sectionElement.Elements())
                {
                    var field = new TemplateElement
                    {
                        Name        = fieldElement.GetAttributeValue("name"),
                        Type        = fieldElement.GetAttributeValue("type"),
                        Unversioned = fieldElement.GetAttributeValue("unversioned") == "1",
                        Shared      = fieldElement.GetAttributeValue("shared") == "1",
                        Source      = fieldElement.GetAttributeValue("source"),
                        ItemUri     = new ItemUri(TemplateUri.DatabaseUri, new ItemId(new Guid(fieldElement.GetAttributeValue("id")))),
                        Icon        = new Icon(TemplateUri.Site, sectionElement.GetAttributeValue("icon"))
                    };

                    if (string.IsNullOrEmpty(field.Type))
                    {
                        field.Type = "Single-Line Text";
                    }

                    FieldsListView.Items.Add(field);
                }
            }

            FieldsListView.ResizeColumn(NameColumn);
            FieldsListView.ResizeColumn(TypeColumn);
            FieldsListView.ResizeColumn(VersioningColumn);
            FieldsListView.ResizeColumn(SourceColumn);

            if (FieldsListView.Items.Count == 0)
            {
                FieldsTextPanel.Visibility      = Visibility.Visible;
                FieldsListViewBorder.Visibility = Visibility.Collapsed;
            }
        }
 private void AddTemplate(TemplateItem item)
 {
     TemplateElement element = new TemplateElement();
     element.Name = item.Name;
     element.Language = item.Language;
     element.Engine = item.Engine;
     element.FileName = item.FileName;
     element.DisplayName = item.DisplayName;
     element.Prefix = item.Prefix;
     element.Suffix = item.Suffix;
     element.Url = item.Url;
     element.Description = item.Description;
     ConfigManager.TemplateSection.Templates.Add(element);
 }
Esempio n. 9
0
        private void AddTemplate(TemplateItem item)
        {
            TemplateElement element = new TemplateElement();

            element.Name        = item.Name;
            element.Language    = item.Language;
            element.Engine      = item.Engine;
            element.FileName    = item.FileName;
            element.DisplayName = item.DisplayName;
            element.Prefix      = item.Prefix;
            element.Suffix      = item.Suffix;
            element.Url         = item.Url;
            element.Description = item.Description;
            ConfigManager.TemplateSection.Templates.Add(element);
        }
Esempio n. 10
0
        /// <summary>
        /// Loads the application's templates.
        /// In the future the application should be set up to call on this method to re-load the templates.
        /// </summary>
        void Initialize(string datafile_sqlite)
        {
            if (CheckPathForErrors(datafile_sqlite))
            {
                return;
            }
            TemplateElement ele;

            Templates.Clear();
            using (SQLiteDb db = new SQLiteDb(datafile_sqlite))
                using (DataSet ds = db.Select("templates", sql_select_templates, SelectTemplatesAdapter))
                    using (DataView v = ds.GetDataView("templates"))
                        foreach (DataRowView rv in v)
                        {
                            Templates.Add(TemplateElement.FromRowView(rv));
                        }
        }
Esempio n. 11
0
        public bool DeleteRow(string path, TemplateElement element)
        {
            bool haserror = false;

            using (SQLiteDb db = new SQLiteDb(path))
                using (SQLiteConnection c = db.Connection)
                    using (SQLiteDataAdapter a = new SQLiteDataAdapter(null, c))
                        using (a.DeleteCommand = new SQLiteCommand(sql_delete_row, c))
                        {
                            try {
                                c.Open();
                                a.DeleteCommand.Parameters.AddWithValue("@xid", element.Id);
                                a.DeleteCommand.ExecuteNonQuery();
                                c.Close();
                            } catch {
                                haserror = true;
                            }
                        }
            return(haserror);
        }
Esempio n. 12
0
        public static void EnsureFlowDirection(ContentControl rootControl)
        {
            if (!LanguageService.IsResourceRightToLeft)
            {
                return;
            }

            var resourceValues = new HashSet <string>(LanguageService.ResourceDictionary.Values);

            foreach (var itemControl in LogicalTreeHelperAddition.EnumerateDescendants <ContentControl>(rootControl)
                     .Select(x => x.Content as ButtonBase)
                     .Where(x => x is not null))
            {
                TemplateElement.SetVisibility(itemControl, Visibility.Visible);

                if (resourceValues.Contains(itemControl.Content))
                {
                    itemControl.FlowDirection = FlowDirection.RightToLeft;
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// SEND TEMPLATE TO SQLITE DATABASE
        /// </summary>
        /// <param name="path"></param>
        static public void UpdateTemplateRow(string path, string tableName, TemplateElement element, string fieldName, string newValue)
        {
            string query = sql_update_row
                           .Replace("@field", fieldName)
                           .Replace("@keyvalue", element.Id.ToString())
                           .Replace("@key", TemplateElement.col_id)
                           .Replace("@table", tableName)
                           //				.Replace("@value", newValue)
            ;

            using (SQLiteDb db = new SQLiteDb(path))
                using (SQLiteConnection c = db.Connection)
                    using (SQLiteDataAdapter a = new SQLiteDataAdapter(null, c))
                        using (a.UpdateCommand = new SQLiteCommand(query, c))
                        {
                            c.Open();
                            a.UpdateCommand.Parameters.AddWithValue("@value", newValue);
                            a.UpdateCommand.ExecuteNonQuery();
                            Debug.Print("{0}", query);
                            c.Close();
                        }
        }
Esempio n. 14
0
        private void SetGenerationSettings(string xmlFileName)
        {
            GenerationSettings settings = SerializeHelper.XmlDeserialize <GenerationSettings>(xmlFileName);

            this.languageCombx.Text              = settings.Language;
            this.templateEngineCombox.Text       = settings.TemplateEngine;
            this.packageTxtBox.Text              = settings.Package;
            this.tablePrefixTxtBox.Text          = settings.TablePrefix;
            this.authorTxtBox.Text               = settings.Author;
            this.versionTxtBox.Text              = settings.Version;
            this.codeFileEncodingCombox.Text     = settings.Encoding;
            this.isOmitTablePrefixChkbox.Checked = settings.IsOmitTablePrefix;
            this.isStandardizeNameChkbox.Checked = settings.IsCamelCaseName;

            this.templateListBox.Items.Clear();
            foreach (string templateName in settings.TemplatesNames)
            {
                TemplateElement     template = ConfigManager.TemplateSection.Templates[templateName];
                TemplateListBoxItem item     = new TemplateListBoxItem(template.Name, template.DisplayName);
                this.templateListBox.Items.Add(item);
                this.templateListBox.SelectedItems.Add(item);
                this.templateListBox.DisplayMember = "DisplayName";
            }
        }
Esempio n. 15
0
 public IfElement(TemplateElement parent) : base(parent)
 {
 }
Esempio n. 16
0
 public BreakElement(TemplateElement parent) : base(parent)
 {
 }
Esempio n. 17
0
        public void LoadTemplate(string template, TemplateModel parameters)
        {
            PassbookGeneratorSection section = ConfigurationManager.GetSection("passbookGenerator") as PassbookGeneratorSection;

            if (section == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("\"passbookGenerator\" section could not be loaded.");
            }

            String path = TemplateModel.MapPath(section.AppleWWDRCACertificate);

            if (File.Exists(path))
            {
                this.AppleWWDRCACertificate = File.ReadAllBytes(path);
            }

            TemplateElement templateConfig = section
                                             .Templates
                                             .OfType <TemplateElement>()
                                             .FirstOrDefault(t => String.Equals(t.Name, template, StringComparison.OrdinalIgnoreCase));

            if (templateConfig == null)
            {
                throw new System.Configuration.ConfigurationErrorsException(String.Format("Configuration for template \"{0}\" could not be loaded.", template));
            }

            this.Style = templateConfig.PassStyle;

            if (this.Style == PassStyle.BoardingPass)
            {
                this.TransitType = templateConfig.TransitType;
            }

            // Certificates
            this.CertificatePassword = templateConfig.CertificatePassword;
            this.CertThumbprint      = templateConfig.CertificateThumbprint;

            path = TemplateModel.MapPath(templateConfig.Certificate);
            if (File.Exists(path))
            {
                this.Certificate = File.ReadAllBytes(path);
            }

            if (String.IsNullOrEmpty(this.CertThumbprint) && this.Certificate == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("Either Certificate or CertificateThumbprint is not configured correctly.");
            }

            // Standard Keys
            this.Description        = templateConfig.Description.Value;
            this.OrganizationName   = templateConfig.OrganizationName.Value;
            this.PassTypeIdentifier = templateConfig.PassTypeIdentifier.Value;
            this.TeamIdentifier     = templateConfig.TeamIdentifier.Value;

            // Associated App Keys
            if (templateConfig.AppLaunchURL != null && !String.IsNullOrEmpty(templateConfig.AppLaunchURL.Value))
            {
                this.AppLaunchURL = templateConfig.AppLaunchURL.Value;
            }

            this.AssociatedStoreIdentifiers.AddRange(templateConfig.AssociatedStoreIdentifiers.OfType <ConfigurationProperty <int> >().Select(s => s.Value));

            // Visual Appearance Keys
            this.BackgroundColor    = templateConfig.BackgroundColor.Value;
            this.ForegroundColor    = templateConfig.ForegroundColor.Value;
            this.GroupingIdentifier = templateConfig.GroupingIdentifier.Value;
            this.LabelColor         = templateConfig.LabelColor.Value;
            this.LogoText           = templateConfig.LogoText.Value;
            this.SuppressStripShine = templateConfig.SuppressStripShine.Value;

            // Web Service Keys
            this.AuthenticationToken = templateConfig.AuthenticationToken.Value;
            this.WebServiceUrl       = templateConfig.WebServiceURL.Value;

            // Fields
            this.AuxiliaryFields.AddRange(TemplateFields(templateConfig.AuxiliaryFields, parameters));
            this.BackFields.AddRange(TemplateFields(templateConfig.BackFields, parameters));
            this.HeaderFields.AddRange(TemplateFields(templateConfig.HeaderFields, parameters));
            this.PrimaryFields.AddRange(TemplateFields(templateConfig.PrimaryFields, parameters));
            this.SecondaryFields.AddRange(TemplateFields(templateConfig.SecondaryFields, parameters));

            // Template Images
            foreach (ImageElement image in templateConfig.Images)
            {
                String imagePath = TemplateModel.MapPath(image.FileName);
                if (File.Exists(imagePath))
                {
                    this.Images[image.Type] = File.ReadAllBytes(imagePath);
                }
            }

            // Model Images (Overwriting template images)
            foreach (KeyValuePair <PassbookImage, byte[]> image in parameters.GetImages())
            {
                this.Images[image.Key] = image.Value;
            }

            // Localization
            foreach (LanguageElement localization in templateConfig.Localizations)
            {
                Dictionary <string, string> values;

                if (!Localizations.TryGetValue(localization.Code, out values))
                {
                    values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                    Localizations.Add(localization.Code, values);
                }

                foreach (LocalizedEntry entry in localization.Localizations)
                {
                    values[entry.Key] = entry.Value;
                }
            }
        }
Esempio n. 18
0
 public ScheduleFormatParser RegisterElement(TemplateElement element)
 {
     _registerElements.Add(element);
     return(this);
 }
Esempio n. 19
0
 public LiteralText(TemplateElement parent) : base(parent)
 {
 }
Esempio n. 20
0
 protected internal override void VisitTemplateElement(TemplateElement templateElement)
 {
     VisitingTemplateElement?.Invoke(this, templateElement);
     base.VisitTemplateElement(templateElement);
     VisitedTemplateElement?.Invoke(this, templateElement);
 }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group to which ads are added.
        /// </param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupAdService.
            AdGroupAdService adGroupAdService =
                (AdGroupAdService)user.GetService(AdWordsService.v201506.AdGroupAdService);

            // Create the template ad.
            TemplateAd clickToDownloadAppAd = new TemplateAd();

            clickToDownloadAppAd.name       = "Ad for demo game";
            clickToDownloadAppAd.templateId = 353;
            clickToDownloadAppAd.finalUrls  = new string[] {
                "http://play.google.com/store/apps/details?id=com.example.demogame"
            };
            clickToDownloadAppAd.displayUrl = "play.google.com";

            // Create the template elements for the ad. You can refer to
            // https://developers.google.com/adwords/api/docs/appendix/templateads
            // for the list of avaliable template fields.
            TemplateElementField headline = new TemplateElementField();

            headline.name      = "headline";
            headline.fieldText = "Enjoy your drive in Mars";
            headline.type      = TemplateElementFieldType.TEXT;

            TemplateElementField description1 = new TemplateElementField();

            description1.name      = "description1";
            description1.fieldText = "Realistic physics simulation";
            description1.type      = TemplateElementFieldType.TEXT;

            TemplateElementField description2 = new TemplateElementField();

            description2.name      = "description2";
            description2.fieldText = "Race against players online";
            description2.type      = TemplateElementFieldType.TEXT;

            TemplateElementField appId = new TemplateElementField();

            appId.name      = "appId";
            appId.fieldText = "com.example.demogame";
            appId.type      = TemplateElementFieldType.TEXT;

            TemplateElementField appStore = new TemplateElementField();

            appStore.name      = "appStore";
            appStore.fieldText = "2";
            appStore.type      = TemplateElementFieldType.ENUM;

            TemplateElement adData = new TemplateElement();

            adData.uniqueName = "adData";
            adData.fields     = new TemplateElementField[] { headline, description1, description2, appId,
                                                             appStore };

            clickToDownloadAppAd.templateElements = new TemplateElement[] { adData };

            // Create the adgroupad.
            AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd();

            clickToDownloadAppAdGroupAd.adGroupId = adGroupId;
            clickToDownloadAppAdGroupAd.ad        = clickToDownloadAppAd;

            // Optional: Set the status.
            clickToDownloadAppAdGroupAd.status = AdGroupAdStatus.PAUSED;

            // Create the operation.
            AdGroupAdOperation operation = new AdGroupAdOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = clickToDownloadAppAdGroupAd;

            try {
                // Create the ads.
                AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[] { operation });

                // Display the results.
                if (retval != null && retval.value != null)
                {
                    foreach (AdGroupAd adGroupAd in retval.value)
                    {
                        Console.WriteLine("New click-to-download ad with id = \"{0}\" and url = \"{1}\" " +
                                          "was created.", adGroupAd.ad.id, adGroupAd.ad.finalUrls[0]);
                    }
                }
                else
                {
                    Console.WriteLine("No click-to-download ads were created.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to create click-to-download ad.", e);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group to which ads are added.
        /// </param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            using (AdGroupAdService adGroupAdService =
                       (AdGroupAdService)user.GetService(AdWordsService.v201806.AdGroupAdService))
            {
                // Create the template ad.
                TemplateAd clickToDownloadAppAd = new TemplateAd
                {
                    name       = "Ad for demo game",
                    templateId = 353,
                    finalUrls  = new string[]
                    {
                        "http://play.google.com/store/apps/details?id=com.example.demogame"
                    },
                    displayUrl = "play.google.com"
                };

                // Create the template elements for the ad. You can refer to
                // https://developers.google.com/adwords/api/docs/appendix/templateads
                // for the list of avaliable template fields.
                TemplateElementField headline = new TemplateElementField
                {
                    name      = "headline",
                    fieldText = "Enjoy your drive in Mars",
                    type      = TemplateElementFieldType.TEXT
                };

                TemplateElementField description1 = new TemplateElementField
                {
                    name      = "description1",
                    fieldText = "Realistic physics simulation",
                    type      = TemplateElementFieldType.TEXT
                };

                TemplateElementField description2 = new TemplateElementField
                {
                    name      = "description2",
                    fieldText = "Race against players online",
                    type      = TemplateElementFieldType.TEXT
                };

                TemplateElementField appId = new TemplateElementField
                {
                    name      = "appId",
                    fieldText = "com.example.demogame",
                    type      = TemplateElementFieldType.TEXT
                };

                TemplateElementField appStore = new TemplateElementField
                {
                    name      = "appStore",
                    fieldText = "2",
                    type      = TemplateElementFieldType.ENUM
                };

                // Optionally specify a landscape image. The image needs to be in a BASE64
                // encoded form. Here we download a demo image and encode it for this ad.
                byte[] imageData =
                    MediaUtilities.GetAssetDataFromUrl("https://goo.gl/9JmyKk", user.Config);
                Image image = new Image
                {
                    data = imageData
                };
                TemplateElementField landscapeImage = new TemplateElementField
                {
                    name       = "landscapeImage",
                    fieldMedia = image,
                    type       = TemplateElementFieldType.IMAGE
                };

                TemplateElement adData = new TemplateElement
                {
                    uniqueName = "adData",
                    fields     = new TemplateElementField[]
                    {
                        headline,
                        description1,
                        description2,
                        appId,
                        appStore,
                        landscapeImage
                    }
                };

                clickToDownloadAppAd.templateElements = new TemplateElement[]
                {
                    adData
                };

                // Create the adgroupad.
                AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd
                {
                    adGroupId = adGroupId,
                    ad        = clickToDownloadAppAd,

                    // Optional: Set the status.
                    status = AdGroupAdStatus.PAUSED
                };

                // Create the operation.
                AdGroupAdOperation operation = new AdGroupAdOperation
                {
                    @operator = Operator.ADD,
                    operand   = clickToDownloadAppAdGroupAd
                };

                try
                {
                    // Create the ads.
                    AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[]
                    {
                        operation
                    });

                    // Display the results.
                    if (retval != null && retval.value != null)
                    {
                        foreach (AdGroupAd adGroupAd in retval.value)
                        {
                            Console.WriteLine(
                                "New click-to-download ad with id = \"{0}\" and url = \"{1}\" " +
                                "was created.", adGroupAd.ad.id, adGroupAd.ad.finalUrls[0]);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No click-to-download ads were created.");
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to create click-to-download ad.",
                                                          e);
                }
            }
        }
Esempio n. 23
0
 public WhenElement(TemplateElement parent) : base(parent)
 {
 }
Esempio n. 24
0
 public virtual void VisitTemplateElement(TemplateElement templateElement)
 {
 }
 public ForEachElement(TemplateElement parent) : base(parent)
 {
 }
Esempio n. 26
0
 public CallElement(TemplateElement parent) : base(parent)
 {
 }
Esempio n. 27
0
 protected virtual void VisitTemplateElement(TemplateElement templateElement)
 {
 }
 private IElementProcessor GetElementProcessor(TemplateElement templateElement)
 {
     return(_processors[templateElement.GetType()]);
 }
Esempio n. 29
0
        public void Deactivate(FlashpointSecurePlayer.MODIFICATIONS_REVERT_METHOD modificationsRevertMethod = FlashpointSecurePlayer.MODIFICATIONS_REVERT_METHOD.CRASH_RECOVERY)
        {
            lock (deactivationLock) {
                // do the reverse of activation because we can
                base.Deactivate();
                TemplateElement activeTemplateElement = GetActiveTemplateElement(false);

                // if the activation backup doesn't exist, we don't need to do stuff
                if (activeTemplateElement == null)
                {
                    return;
                }

                ModificationsElement activeModificationsElement = activeTemplateElement.Modifications;

                if (activeModificationsElement.EnvironmentVariables.Count <= 0)
                {
                    return;
                }

                // if the activation backup exists, but no key is marked as active...
                // we assume the registry has changed, and don't revert the changes, to be safe
                // (it should never happen unless the user tampered with the config file)
                string templateElementName = activeTemplateElement.Active;

                // don't allow infinite recursion!
                if (String.IsNullOrEmpty(templateElementName))
                {
                    activeModificationsElement.EnvironmentVariables.Clear();
                    SetFlashpointSecurePlayerSection(TemplateName);
                    return;
                }

                TemplateElement      templateElement      = GetTemplateElement(false, templateElementName);
                ModeElement          modeElement          = templateElement.Mode;
                ModificationsElement modificationsElement = null;

                // if the active element pointed to doesn't exist... same assumption
                // and another safeguard against recursion
                if (templateElement != null && templateElement != activeTemplateElement)
                {
                    if (templateElement.Modifications.ElementInformation.IsPresent)
                    {
                        modificationsElement = templateElement.Modifications;
                    }
                }

                if (modificationsElement == null)
                {
                    activeModificationsElement.EnvironmentVariables.Clear();
                    SetFlashpointSecurePlayerSection(TemplateName);
                    return;
                }

                // initialize variables
                string        comparableName           = null;
                string        value                    = null;
                List <string> values                   = null;
                string        compatibilityLayerValue  = null;
                List <string> compatibilityLayerValues = new List <string>();

                // compatibility settings
                try {
                    compatibilityLayerValue = Environment.GetEnvironmentVariable(__COMPAT_LAYER, EnvironmentVariableTarget.Process);
                } catch (ArgumentException) {
                    throw new EnvironmentVariablesFailedException("Failed to get the " + __COMPAT_LAYER + " Environment Variable.");
                } catch (SecurityException) {
                    throw new TaskRequiresElevationException("Getting the " + __COMPAT_LAYER + " Environment Variable requires elevation.");
                }

                // we get this right away here
                // as opposed to after the variable has been potentially set like during activation
                if (compatibilityLayerValue != null)
                {
                    compatibilityLayerValues = compatibilityLayerValue.ToUpperInvariant().Split(' ').ToList();
                }

                ProgressManager.CurrentGoal.Start(activeModificationsElement.EnvironmentVariables.Count);

                try {
                    EnvironmentVariablesElement environmentVariablesElement       = null;
                    EnvironmentVariablesElement activeEnvironmentVariablesElement = null;

                    for (int i = 0; i < activeModificationsElement.EnvironmentVariables.Count; i++)
                    {
                        environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;

                        if (environmentVariablesElement == null)
                        {
                            throw new EnvironmentVariablesFailedException("The Environment Variable element (" + i + ") is null.");
                        }

                        activeEnvironmentVariablesElement = activeModificationsElement.EnvironmentVariables.Get(environmentVariablesElement.Name) as EnvironmentVariablesElement;

                        if (activeEnvironmentVariablesElement != null)
                        {
                            comparableName = GetComparableName(activeEnvironmentVariablesElement.Name);

                            if (UnmodifiableComparableNames.Contains(comparableName))
                            {
                                throw new EnvironmentVariablesFailedException("The " + activeEnvironmentVariablesElement.Name + " Environment Variable cannot be modified at this time.");
                            }

                            value  = environmentVariablesElement.Value;
                            values = new List <string>();

                            if (value != null)
                            {
                                values = value.ToUpperInvariant().Split(' ').ToList();
                            }

                            if (modificationsRevertMethod == FlashpointSecurePlayer.MODIFICATIONS_REVERT_METHOD.DELETE_ALL)
                            {
                                try {
                                    Environment.SetEnvironmentVariable(activeEnvironmentVariablesElement.Name, null, EnvironmentVariableTarget.Process);
                                } catch (ArgumentException) {
                                    throw new EnvironmentVariablesFailedException("Failed to delete the " + environmentVariablesElement.Name + " Environment Variable.");
                                } catch (SecurityException) {
                                    throw new TaskRequiresElevationException("Deleting the " + environmentVariablesElement.Name + " Environment Variable requires elevation.");
                                }
                            }
                            else
                            {
                                // don't reset Compatibility Settings if we're restarting for Web Browser Mode
                                if (comparableName != __COMPAT_LAYER || values.Except(compatibilityLayerValues).Any() || modeElement.Name != ModeElement.NAME.WEB_BROWSER)
                                {
                                    try {
                                        Environment.SetEnvironmentVariable(activeEnvironmentVariablesElement.Name, activeEnvironmentVariablesElement.Value, EnvironmentVariableTarget.Process);
                                    } catch (ArgumentException) {
                                        throw new EnvironmentVariablesFailedException("Failed to set the " + environmentVariablesElement.Name + " Environment Variable.");
                                    } catch (SecurityException) {
                                        throw new TaskRequiresElevationException("Setting the " + environmentVariablesElement.Name + " Environment Variable requires elevation.");
                                    }
                                }
                            }

                            ProgressManager.CurrentGoal.Steps++;
                        }
                    }

                    activeModificationsElement.EnvironmentVariables.Clear();
                    SetFlashpointSecurePlayerSection(TemplateName);
                } finally {
                    ProgressManager.CurrentGoal.Stop();
                }
            }
        }
Esempio n. 30
0
        new public void Activate(string templateName)
        {
            lock (activationLock) {
                base.Activate(templateName);

                // validation
                if (String.IsNullOrEmpty(TemplateName))
                {
                    // no argument
                    return;
                }

                // initialize templates
                TemplateElement templateElement = GetTemplateElement(false, TemplateName);

                if (templateElement == null)
                {
                    return;
                }

                ModeElement          modeElement          = templateElement.Mode;
                ModificationsElement modificationsElement = templateElement.Modifications;

                if (!modificationsElement.ElementInformation.IsPresent)
                {
                    return;
                }

                TemplateElement      activeTemplateElement      = GetActiveTemplateElement(true, TemplateName);
                ModificationsElement activeModificationsElement = activeTemplateElement.Modifications;

                // initialize variables
                string        comparableName           = null;
                string        value                    = null;
                List <string> values                   = null;
                string        compatibilityLayerValue  = null;
                List <string> compatibilityLayerValues = new List <string>();

                // compatibility settings
                try {
                    // we need to find the compatibility layers so we can check later if the ones we want are already set
                    compatibilityLayerValue = Environment.GetEnvironmentVariable(__COMPAT_LAYER, EnvironmentVariableTarget.Process);
                } catch (ArgumentException) {
                    throw new EnvironmentVariablesFailedException("Failed to get the " + __COMPAT_LAYER + " Environment Variable.");
                } catch (SecurityException) {
                    throw new TaskRequiresElevationException("Getting the " + __COMPAT_LAYER + " Environment Variable requires elevation.");
                }

                ProgressManager.CurrentGoal.Start(modificationsElement.EnvironmentVariables.Count + modificationsElement.EnvironmentVariables.Count);

                try {
                    EnvironmentVariablesElement activeEnvironmentVariablesElement = null;
                    EnvironmentVariablesElement environmentVariablesElement       = null;

                    // set active configuration
                    for (int i = 0; i < modificationsElement.EnvironmentVariables.Count; i++)
                    {
                        environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;

                        if (environmentVariablesElement == null)
                        {
                            throw new System.Configuration.ConfigurationErrorsException("The Environment Variables Element (" + i + ") is null while creating the Active Environment Variables Element.");
                        }

                        comparableName = GetComparableName(environmentVariablesElement.Name);

                        if (UnmodifiableComparableNames.Contains(comparableName))
                        {
                            throw new EnvironmentVariablesFailedException("The " + environmentVariablesElement.Name + " Environment Variable cannot be modified while creating the Active Environment Variables Element.");
                        }

                        try {
                            activeEnvironmentVariablesElement = new EnvironmentVariablesElement {
                                Name  = environmentVariablesElement.Name,
                                Find  = environmentVariablesElement.Find,
                                Value = Environment.GetEnvironmentVariable(environmentVariablesElement.Name, EnvironmentVariableTarget.Process)
                            };
                        } catch (ArgumentException) {
                            throw new EnvironmentVariablesFailedException("Failed to get the " + environmentVariablesElement.Name + " Environment Variable.");
                        } catch (SecurityException) {
                            throw new TaskRequiresElevationException("Getting the " + environmentVariablesElement.Name + " Environment Variable requires elevation.");
                        }

                        activeModificationsElement.EnvironmentVariables.Set(activeEnvironmentVariablesElement);
                        ProgressManager.CurrentGoal.Steps++;
                    }

                    SetFlashpointSecurePlayerSection(TemplateName);

                    // set environment variables
                    for (int i = 0; i < modificationsElement.EnvironmentVariables.Count; i++)
                    {
                        environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;

                        if (environmentVariablesElement == null)
                        {
                            throw new System.Configuration.ConfigurationErrorsException("The Environment Variables Element (" + i + ") is null.");
                        }

                        comparableName = GetComparableName(environmentVariablesElement.Name);

                        if (UnmodifiableComparableNames.Contains(comparableName))
                        {
                            throw new EnvironmentVariablesFailedException("The " + environmentVariablesElement.Name + " Environment Variable cannot be modified at this time.");
                        }

                        value = GetValue(environmentVariablesElement);

                        try {
                            Environment.SetEnvironmentVariable(environmentVariablesElement.Name, Environment.ExpandEnvironmentVariables(value), EnvironmentVariableTarget.Process);
                        } catch (ArgumentException) {
                            throw new EnvironmentVariablesFailedException("Failed to set the " + environmentVariablesElement.Name + " Environment Variable.");
                        } catch (SecurityException) {
                            throw new TaskRequiresElevationException("Setting the " + environmentVariablesElement.Name + " Environment Variable requires elevation.");
                        }

                        // now throw up a restart in Web Browser Mode for Compatibility Settings
                        if (comparableName == __COMPAT_LAYER && modeElement.Name == ModeElement.NAME.WEB_BROWSER)
                        {
                            values = new List <string>();

                            // the compatibility layers may contain more values
                            // but we're only concerned if it contains the values we want
                            if (compatibilityLayerValue != null)
                            {
                                compatibilityLayerValues = compatibilityLayerValue.ToUpperInvariant().Split(' ').ToList();
                            }

                            if (value != null)
                            {
                                values = value.ToUpperInvariant().Split(' ').ToList();
                            }

                            // we have to restart in this case in server mode
                            // because the compatibility layers only take effect
                            // on process start
                            if (values.Except(compatibilityLayerValues).Any())
                            {
                                throw new CompatibilityLayersException("The Compatibility Layers (" + value + ") cannot be set.");
                            }
                        }

                        ProgressManager.CurrentGoal.Steps++;
                    }
                } finally {
                    ProgressManager.CurrentGoal.Stop();
                }
            }
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="adGroupId">Id of the ad group to which ads are added.
    /// </param>
    public void Run(AdWordsUser user, long adGroupId) {
      // Get the AdGroupAdService.
      AdGroupAdService adGroupAdService =
          (AdGroupAdService) user.GetService(AdWordsService.v201509.AdGroupAdService);

      // Create the template ad.
      TemplateAd clickToDownloadAppAd = new TemplateAd();

      clickToDownloadAppAd.name = "Ad for demo game";
      clickToDownloadAppAd.templateId = 353;
      clickToDownloadAppAd.finalUrls = new string[] {
          "http://play.google.com/store/apps/details?id=com.example.demogame"
      };
      clickToDownloadAppAd.displayUrl = "play.google.com";

      // Create the template elements for the ad. You can refer to
      // https://developers.google.com/adwords/api/docs/appendix/templateads
      // for the list of avaliable template fields.
      TemplateElementField headline = new TemplateElementField();
      headline.name = "headline";
      headline.fieldText = "Enjoy your drive in Mars";
      headline.type = TemplateElementFieldType.TEXT;

      TemplateElementField description1 = new TemplateElementField();
      description1.name = "description1";
      description1.fieldText = "Realistic physics simulation";
      description1.type = TemplateElementFieldType.TEXT;

      TemplateElementField description2 = new TemplateElementField();
      description2.name = "description2";
      description2.fieldText = "Race against players online";
      description2.type = TemplateElementFieldType.TEXT;

      TemplateElementField appId = new TemplateElementField();
      appId.name = "appId";
      appId.fieldText = "com.example.demogame";
      appId.type = TemplateElementFieldType.TEXT;

      TemplateElementField appStore = new TemplateElementField();
      appStore.name = "appStore";
      appStore.fieldText = "2";
      appStore.type = TemplateElementFieldType.ENUM;

      TemplateElement adData = new TemplateElement();
      adData.uniqueName = "adData";
      adData.fields = new TemplateElementField[] {headline, description1, description2, appId,
          appStore};

      clickToDownloadAppAd.templateElements = new TemplateElement[] {adData};

      // Create the adgroupad.
      AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd();
      clickToDownloadAppAdGroupAd.adGroupId = adGroupId;
      clickToDownloadAppAdGroupAd.ad = clickToDownloadAppAd;

      // Optional: Set the status.
      clickToDownloadAppAdGroupAd.status = AdGroupAdStatus.PAUSED;

      // Create the operation.
      AdGroupAdOperation operation = new AdGroupAdOperation();
      operation.@operator = Operator.ADD;
      operation.operand = clickToDownloadAppAdGroupAd;

      try {
        // Create the ads.
        AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[] {operation});

        // Display the results.
        if (retval != null && retval.value != null) {
          foreach (AdGroupAd adGroupAd in retval.value) {
            Console.WriteLine("New click-to-download ad with id = \"{0}\" and url = \"{1}\" " +
                "was created.", adGroupAd.ad.id, adGroupAd.ad.finalUrls[0]);
          }
        } else {
          Console.WriteLine("No click-to-download ads were created.");
        }
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to create click-to-download ad.", e);
      }
    }
Esempio n. 32
0
 /// <summary>
 /// Determines whether the specified line is transaction.
 /// </summary>
 /// <param name="line">The line.</param>
 /// <param name="template">The template.</param>
 /// <returns></returns>
 public static Boolean IsTransaction(String line, TemplateElement template)
 {
     return(line.Contains(template.Type));
 }