public void Setup()
 {
     sp  = new SourceProperties();
     dp  = new DestinationProperties();
     opt = new Options();
     Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\"));
 }
Пример #2
0
 public bool Equals(Finding other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     if (ReferenceEquals(other, this))
     {
         return(true);
     }
     if (Name != other.Name)
     {
         return(false);
     }
     if (Parent != other.Parent)
     {
         return(false);
     }
     if (ResourceName != other.ResourceName)
     {
         return(false);
     }
     if (State != other.State)
     {
         return(false);
     }
     if (Category != other.Category)
     {
         return(false);
     }
     if (ExternalUri != other.ExternalUri)
     {
         return(false);
     }
     if (!SourceProperties.Equals(other.SourceProperties))
     {
         return(false);
     }
     if (!object.Equals(SecurityMarks, other.SecurityMarks))
     {
         return(false);
     }
     if (!object.Equals(EventTime, other.EventTime))
     {
         return(false);
     }
     if (!object.Equals(CreateTime, other.CreateTime))
     {
         return(false);
     }
     if (Severity != other.Severity)
     {
         return(false);
     }
     if (CanonicalName != other.CanonicalName)
     {
         return(false);
     }
     return(Equals(_unknownFields, other._unknownFields));
 }
Пример #3
0
        public string FromObjectToGeoJSON(IEnumerable <Source> sources)
        {
            try
            {
                SourceFeatureCollection sourceFeatureCollection = new SourceFeatureCollection();
                sourceFeatureCollection.Features = new SourceFeature[sources.Count()];

                int i = 0;
                foreach (Source source in sources)
                {
                    SourceFeature    sourceFeature = new SourceFeature();
                    SourceProperties properties    = new SourceProperties();
                    properties.SourceDirection          = source.SourceDirection;
                    properties.SourceName               = source.SourceName;
                    properties.IsOnLine                 = source.IsOnline.ToString();
                    sourceFeature.Properties            = properties;
                    sourceFeatureCollection.Features[i] = sourceFeature;
                    i++;
                }
                StringBuilder Builder = new System.Text.StringBuilder();
                StringWriter  Writer  = new System.IO.StringWriter(Builder);

                new JsonSerializer().Serialize(Writer, sourceFeatureCollection);

                return(Builder.ToString());
            }
            catch (Exception ex)
            {
                ExceptionUtility.Warn(ex, this.GetType());
                return(ExceptionUtility.BadRequestMessage);
            }
        }
Пример #4
0
 static void SetPropertiesAl(uint src, ref SourceProperties prop, int flags)
 {
     if ((flags & FLAG_POS) == FLAG_POS)
     {
         Al.alSourcei(src, Al.AL_SOURCE_RELATIVE, prop.Is3D ? 0 : 1);
         Al.alSource3f(src, Al.AL_POSITION, prop.Position.X, prop.Position.Y, prop.Position.Z);
     }
     if ((flags & FLAG_VEL) == FLAG_VEL)
     {
         Al.alSource3f(src, Al.AL_VELOCITY, prop.Velocity.X, prop.Velocity.Y, prop.Velocity.Z);
     }
     if ((flags & FLAG_DIRECTION) == FLAG_DIRECTION)
     {
         Al.alSource3f(src, Al.AL_DIRECTION, prop.Direction.X, prop.Direction.Y, prop.Direction.Z);
     }
     if ((flags & FLAG_GAIN) == FLAG_GAIN)
     {
         Al.alSourcef(src, Al.AL_GAIN, prop.Gain);
     }
     if ((flags & FLAG_PITCH) == FLAG_PITCH)
     {
         Al.alSourcef(src, Al.AL_PITCH, prop.Pitch);
     }
     if ((flags & FLAG_DIST) == FLAG_DIST)
     {
         Al.alSourcef(src, Al.AL_REFERENCE_DISTANCE, prop.ReferenceDistance);
         Al.alSourcef(src, Al.AL_MAX_DISTANCE, prop.MaxDistance);
     }
     if ((flags & FLAG_CONE) == FLAG_CONE)
     {
         Al.alSourcef(src, Al.AL_CONE_INNER_ANGLE, prop.ConeInnerAngle);
         Al.alSourcef(src, Al.AL_CONE_OUTER_ANGLE, prop.ConeOuterAngle);
         Al.alSourcef(src, Al.AL_CONE_OUTER_GAIN, prop.ConeOuterGain);
     }
 }
Пример #5
0
        private void CheckPropertyFlattening(IEnumerable <PropertyInfo> sourceProperties, PropertyInfo targetProperty)
        {
            var stack = new Stack <(IEnumerable <PropertyInfo>, string, Expression)>();

            stack.Push((sourceProperties, targetProperty.Name, SourceParameter));

            while (stack.Any())
            {
                var(SourceProperties, CurrentName, PropertyChain) = stack.Pop();

                if (SourceProperties.Any(p => p.Name == CurrentName))
                {
                    var sourceProperty = SourceProperties.FirstOrDefault(p => p.Name == CurrentName && p.PropertyType == targetProperty.PropertyType);
                    if (sourceProperty != null)
                    {
                        Bindings.Add(new MemberBinding
                        {
                            SourceExpression = Expression.Property(PropertyChain, sourceProperty),
                            TargetMember     = targetProperty
                        });
                    }
                }
                else if (SourceProperties.Any(p => CurrentName.StartsWith(p.Name)))
                {
                    foreach (var property in SourceProperties.Where(p => CurrentName.StartsWith(p.Name)))
                    {
                        var newName = CurrentName.Substring(property.Name.Length);
                        stack.Push((property.PropertyType.GetProperties(), newName, Expression.Property(PropertyChain, property)));
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Create new resolver with new properties, use original key value pairs
        /// </summary>
        /// <param name="values"></param>
        /// <param name="propertyUpdate">Update property mode</param>
        /// <returns>new property resolver</returns>
        public IPropertyResolver With(IEnumerable <KeyValuePair <string, string> > values, PropertyUpdate propertyUpdate)
        {
            values.Verify(nameof(values)).IsNotNull();

            if (!values.Any())
            {
                return(this);
            }

            switch (propertyUpdate)
            {
            case PropertyUpdate.FailOnDuplicate:
                return(new PropertyResolver(SourceProperties.Concat(values), _comparer, Strict));

            case PropertyUpdate.IgnoreDuplicate:
                IEnumerable <KeyValuePair <string, string> > newValues = SourceProperties.Concat(values.Where(x => !SourceProperties.ContainsKey(x.Key)));
                return(new PropertyResolver(newValues, _comparer, Strict));

            case PropertyUpdate.Overwrite:
                var overwriteValues = values.Select(x => new { Index = 0, Value = x })
                                      .Concat(SourceProperties.Select(x => new { Index = 1, Value = x }))
                                      .GroupBy(x => x.Value.Key)
                                      .Select(x => x.OrderBy(y => y.Index).Select(z => z.Value).First())
                                      .ToList();

                return(new PropertyResolver(overwriteValues, _comparer, Strict));

            default:
                throw new ArgumentException($"Invalided propertyUpdate={propertyUpdate}");
            }
        }
        private void PlaceSource(Source source, double offset, int y, double cellWidth)
        {
            SourceUserControl sourceControl = new SourceUserControl();

            double var = 80 * cellWidth / 100;

            if (var > startHeight)
            {
                currentHeight = startHeight;
            }
            else
            {
                currentHeight = var;
            }

            if (properties.TryGetValue(source.ElementGID, out ElementProperties elementProperties))
            {
                SourceProperties sourceProperties = elementProperties as SourceProperties;

                sourceControl.DataContext = sourceProperties;
            }

            sourceControl.Button.Width  = currentHeight;
            sourceControl.Button.Height = currentHeight;

            Canvas.SetLeft(sourceControl, offset + cellWidth / 2 - currentHeight / 2);
            Canvas.SetTop(sourceControl, y * cellHeight - cellHeight / 5 + currentHeight);
            Panel.SetZIndex(sourceControl, 5);

            sourceControl.Button.Command          = NetworkViewViewModel.OpenPropertiesCommand;
            sourceControl.Button.CommandParameter = source.ElementGID;
            sourceControl.ToolTip = source.MRID;

            result.Add(sourceControl);
        }
Пример #8
0
        void SetSourceProperties(SourceProperties prop, int flags)
        {
            var src = man.AM_GetInstanceSource(ID, false);

            if (src != uint.MaxValue)
            {
                SetPropertiesAl(src, ref prop, flags);
            }
        }
Пример #9
0
 /// <summary>
 /// Setup framework.ini values.
 /// </summary>
 private static void Initialize(FrameworkIni frameworkIni, SourceProperties sourceProperties, SdkProperties sdkProperties)
 {
     frameworkIni.Target   = "android-" + sourceProperties.ApiLevel;
     frameworkIni.ApiLevel = int.Parse(sourceProperties.ApiLevel);
     foreach (var key in sdkProperties.Keys.Where(x => !x.Contains(".ant.")))
     {
         frameworkIni[key] = sdkProperties[key];
     }
 }
Пример #10
0
        /// <summary>
        /// Create Dot42.dll
        /// </summary>
        private static void CreateFrameworkAssembly(JarFile jf, DocModel xmlModel, SourceProperties sourceProperties, string folder)
        {
            // Initialize all
            MappedTypeBuilder.Initialize(CompositionContainer);

            // Create java type wrappers
            var module      = new NetModule(AttributeConstants.Dot42Scope);
            var classLoader = new AssemblyClassLoader(null);
            var target      = new TargetFramework(null, classLoader, xmlModel, LogMissingParamNamesType, true, false, Enumerable.Empty <string>());

            List <TypeBuilder> typeBuilders;

            using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Create()", x.TotalMilliseconds)))
            {
                var classTypeBuilders = jf.ClassNames.SelectMany(n => StandardTypeBuilder.Create(jf.LoadClass(n), target));
                var customTypeBuilder = CompositionContainer.GetExportedValues <ICustomTypeBuilder>()
                                        .OrderBy(x => x.CustomTypeName)
                                        .Select(x => x.AsTypeBuilder());

                typeBuilders = classTypeBuilders.Concat(customTypeBuilder)
                               .OrderBy(x => x.Priority)
                               .ToList();



                typeBuilders.ForEach(x => x.CreateType(null, module, target));
            }

            // Create JavaRef attribute
            //JavaRefAttributeBuilder.Build(asm.MainModule);

            // Implement and finalize types
            using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Implement()", x.TotalMilliseconds)))
            {
                JarImporter.Implement(typeBuilders, target);
            }

            // Save
            using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Generate()", x.TotalMilliseconds)))
            {
                CodeGenerator.Generate(folder, module.Types, new List <NetCustomAttribute>(), target, new FrameworkCodeGeneratorContext(), target);
            }

            // Create layout.xml
            var doc = new XDocument(new XElement("layout"));

            typeBuilders.ForEach(x => x.FillLayoutXml(jf, doc.Root));
            doc.Save(Path.Combine(folder, "layout.xml"));

            // create dot42.typemap
            doc = new XDocument(new XElement("typemap"));
            typeBuilders.ForEach(x => x.FillTypemapXml(jf, doc.Root));
            doc.Save(Path.Combine(folder, "dot42.typemap"));
            //using (var s = new FileStream(Path.Combine(folder, "dot42.typemap"), FileMode.Create))
            //    CompressedXml.WriteTo(doc, s, Encoding.UTF8);
        }
Пример #11
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Parent.Length != 0)
            {
                hash ^= Parent.GetHashCode();
            }
            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (State != global::Google.Cloud.SecurityCenter.V1P1Beta1.Finding.Types.State.Unspecified)
            {
                hash ^= State.GetHashCode();
            }
            if (Category.Length != 0)
            {
                hash ^= Category.GetHashCode();
            }
            if (ExternalUri.Length != 0)
            {
                hash ^= ExternalUri.GetHashCode();
            }
            hash ^= SourceProperties.GetHashCode();
            if (securityMarks_ != null)
            {
                hash ^= SecurityMarks.GetHashCode();
            }
            if (eventTime_ != null)
            {
                hash ^= EventTime.GetHashCode();
            }
            if (createTime_ != null)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (Severity != global::Google.Cloud.SecurityCenter.V1P1Beta1.Finding.Types.Severity.Unspecified)
            {
                hash ^= Severity.GetHashCode();
            }
            if (CanonicalName.Length != 0)
            {
                hash ^= CanonicalName.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #12
0
        ///GENMHASH:30C98FF9034C1FF1815B95FA5BA504A9:12DFBCBE7D8A63F0C3680DEAB462A319
        internal SourceUpdateParameters SourcePropertiesToSourceUpdateParameters(SourceProperties sourceProperties)
        {
            SourceUpdateParameters sourceUpdateParameters = new SourceUpdateParameters
            {
                SourceControlType           = sourceProperties.SourceControlType,
                RepositoryUrl               = sourceProperties.RepositoryUrl,
                Branch                      = sourceProperties.Branch,
                SourceControlAuthProperties = null
            };

            return(sourceUpdateParameters);
        }
Пример #13
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Parent.Length != 0)
            {
                hash ^= Parent.GetHashCode();
            }
            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (State != 0)
            {
                hash ^= State.GetHashCode();
            }
            if (Category.Length != 0)
            {
                hash ^= Category.GetHashCode();
            }
            if (ExternalUri.Length != 0)
            {
                hash ^= ExternalUri.GetHashCode();
            }
            hash ^= SourceProperties.GetHashCode();
            if (securityMarks_ != null)
            {
                hash ^= SecurityMarks.GetHashCode();
            }
            if (eventTime_ != null)
            {
                hash ^= EventTime.GetHashCode();
            }
            if (createTime_ != null)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #14
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            EncoderDevice video = null;
            EncoderDevice audio = null;

            GetSelectedVideoAndAudioDevices(out video, out audio);
            StopJob();

            if (video == null)
            {
                return;
            }

            // Starts new job for preview window
            _job = new LiveJob();

            // Checks for a/v devices
            if (video != null && audio != null)
            {
                // Create a new device source. We use the first audio and video devices on the system
                _deviceSource = _job.AddDeviceSource(video, audio);

                // Is it required to show the configuration dialogs ?
                if (checkBoxShowConfigDialog.Checked)
                {
                    // Yes
                    // VFW video device ?
                    if (lstVideoDevices.SelectedItem.ToString().EndsWith("(VFW)", StringComparison.OrdinalIgnoreCase))
                    {
                        // Yes
                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VfwFormatDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VfwFormatDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }

                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VfwSourceDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VfwSourceDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }

                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VfwDisplayDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VfwDisplayDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }
                    }
                    else
                    {
                        // No
                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VideoCapturePinDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoCapturePinDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }

                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VideoCaptureDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoCaptureDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }

                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VideoCrossbarDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoCrossbarDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }

                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VideoPreviewPinDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoPreviewPinDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }

                        if (_deviceSource.IsDialogSupported(ConfigurationDialog.VideoSecondCrossbarDialog))
                        {
                            _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoSecondCrossbarDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
                        }
                    }
                }
                else
                {
                    // No
                    // Setup the video resolution and frame rate of the video device
                    // NOTE: Of course, the resolution and frame rate you specify must be supported by the device!
                    // NOTE2: May be not all video devices support this call, and so it just doesn't work, as if you don't call it (no error is raised)
                    // NOTE3: As a workaround, if the .PickBestVideoFormat method doesn't work, you could force the resolution in the
                    //        following instructions (called few lines belows): 'panelVideoPreview.Size=' and '_job.OutputFormat.VideoProfile.Size='
                    //        to be the one you choosed (640, 480).
                    //xyz
                    _deviceSource.PickBestVideoFormat(new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height), 15);
                }

                // Get the properties of the device video
                SourceProperties sp = _deviceSource.SourcePropertiesSnapshot();

                // Resize the preview panel to match the video device resolution set
                panelVideoPreview.Size = new Size(sp.Size.Width, sp.Size.Height);

                // Setup the output video resolution file as the preview
                _job.OutputFormat.VideoProfile.Size = new Size(sp.Size.Width, sp.Size.Height);

                // Display the video device properties set
                toolStripStatusLabel1.Text = sp.Size.Width.ToString() + "x" + sp.Size.Height.ToString() + "  " + sp.FrameRate.ToString() + " fps";

                // Sets preview window to winform panel hosted by xaml window
                _deviceSource.PreviewWindow = new PreviewWindow(new HandleRef(panelVideoPreview, panelVideoPreview.Handle));

                // Make this source the active one
                _job.ActivateSource(_deviceSource);

                btnStartStopRecording.Enabled = true;
                btnGrabImage.Enabled          = true;

                toolStripStatusLabel1.Text = "Preview activated";
            }
            else
            {
                // Gives error message as no audio and/or video devices found
                MessageBox.Show("No Video/Audio capture devices have been found.", "Warning");
                toolStripStatusLabel1.Text = "No Video/Audio capture devices have been found.";
            }
        }
Пример #15
0
        private void btnGrabar_Click(object sender, EventArgs e)
        {
            if (ID <= 0)
            {
                return;
            }

            btnGrabar.Enabled  = false;
            btnDetener.Enabled = true;

            try
            {
                ListaDispositivos = new List <ObjVideo>();

                foreach (var item in ugDispositivos.Rows)
                {
                    item.Cells["Estado"].Value = "Grabando...";
                    ObjVideo dispositivo = new ObjVideo();

                    EncoderDevice video = null;
                    EncoderDevice audio = null;

                    GetSelectedVideoAndAudioDevices(out video, out audio, item.Cells["ID"].Value.ToString());

                    if (video == null)
                    {
                        return;
                    }

                    dispositivo.Job = new LiveJob();

                    if (!dispositivo.BStartedRecording)
                    {
                        if (video != null)
                        {
                            dispositivo.DeviceSource = dispositivo.Job.AddDeviceSource(video, audio);

                            dispositivo.DeviceSource.PickBestVideoFormat(new Size(1280, 720), 1);
                            SourceProperties sp = dispositivo.DeviceSource.SourcePropertiesSnapshot();
                            dispositivo.Job.OutputFormat.VideoProfile.Size = new Size(sp.Size.Width, sp.Size.Height);
                            dispositivo.Job.ActivateSource(dispositivo.DeviceSource);
                        }
                        else
                        {
                            MessageBox.Show("No Video/Audio capture devices have been found.", "Warning");
                        }
                    }

                    if (dispositivo.BStartedRecording)
                    {
                        dispositivo.Job.StopEncoding();
                        dispositivo.BStartedRecording = false;
                        video = null;
                        audio = null;
                    }
                    else
                    {
                        FileArchivePublishFormat fileOut = new FileArchivePublishFormat();
                        Random rnd = new Random();
                        dispositivo.FileName = "C:\\Video\\CAM{0:yyyyMMdd_hhmmss}-" + rnd.Next(10) + ".wmv";

                        fileOut.OutputFileName = String.Format(dispositivo.FileName, DateTime.Now);

                        dispositivo.FileName = fileOut.OutputFileName;

                        dispositivo.Job.PublishFormats.Add(fileOut);
                        dispositivo.Job.StartEncoding();

                        dispositivo.BStartedRecording = true;
                    }

                    dispositivo.Id = item.Cells["ID"].Value.ToString();
                    ListaDispositivos.Add(dispositivo);
                }
            }
            catch (Exception ex)
            {
                btnDetener.Enabled = true;
                btnGrabar.Enabled  = false;
                ListaDispositivos.Clear();
                ListaDispositivos = null;

                this.SetMensaje(ex.Message, 5000, Color.Red, Color.White);
            }
        }
        public Dictionary <long, ElementProperties> InitElementProperties(List <Element> elements)
        {
            if (elements != null)
            {
                foreach (Element element in elements)
                {
                    if (element is Switch)
                    {
                        Switch           @switch          = (Switch)element;
                        SwitchProperties switchProperties = new SwitchProperties()
                        {
                            GID          = @switch.ElementGID,
                            IsEnergized  = @switch.IsEnergized,
                            IsUnderScada = @switch.UnderSCADA,
                            Incident     = @switch.Incident,
                            CanCommand   = @switch.CanCommand,
                            ParentGid    = @switch.End1
                        };

                        properties.Add(switchProperties.GID, switchProperties);
                    }
                    else if (element is Consumer)
                    {
                        Consumer           consumer           = (Consumer)element;
                        ConsumerProperties consumerProperties = new ConsumerProperties()
                        {
                            GID          = consumer.ElementGID,
                            IsEnergized  = consumer.IsEnergized,
                            IsUnderScada = consumer.UnderSCADA,
                            Call         = false
                        };

                        properties.Add(consumerProperties.GID, consumerProperties);
                    }
                    else if (element is Source)
                    {
                        Source           source           = (Source)element;
                        SourceProperties sourceProperties = new SourceProperties()
                        {
                            GID          = source.ElementGID,
                            IsEnergized  = source.IsEnergized,
                            IsUnderScada = source.UnderSCADA
                        };

                        properties.Add(sourceProperties.GID, sourceProperties);
                    }
                    else if (element is ACLine)
                    {
                        ACLine           acLine           = (ACLine)element;
                        ACLineProperties acLineProperties = new ACLineProperties()
                        {
                            GID          = acLine.ElementGID,
                            IsEnergized  = acLine.IsEnergized,
                            IsUnderScada = acLine.UnderSCADA
                        };

                        properties.Add(acLineProperties.GID, acLineProperties);
                    }
                    else if (element is Node)
                    {
                        Node           node           = (Node)element;
                        NodeProperties nodeProperties = new NodeProperties()
                        {
                            GID         = node.ElementGID,
                            IsEnergized = node.IsEnergized
                        };

                        properties.Add(nodeProperties.GID, nodeProperties);
                    }
                }
            }

            foreach (Model.Properties.DMSProperties.ElementProperties property in properties.Values)
            {
                if (property is SwitchProperties)
                {
                    properties.TryGetValue(((SwitchProperties)property).ParentGid, out ElementProperties elementProperties);

                    if (elementProperties != null)
                    {
                        ((SwitchProperties)property).Parent = elementProperties;
                    }
                }
            }

            return(properties);
        }
Пример #17
0
        /// <summary>
        /// Entry point
        /// </summary>
        internal static int Main(string[] args)
        {
            try
            {
#if DEBUG
                if (args.Length == 0)
                {
                    var assemblyFolder          = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                    var folder                  = Path.GetFullPath(Path.Combine(assemblyFolder, @"..\..\..\..\Sources\Framework\Generated"));
                    var sdkRoot                 = Path.GetFullPath(Path.Combine(assemblyFolder, @"..\..\..\..\Binaries"));
                    var xmlFolder               = Path.GetFullPath(Path.Combine(assemblyFolder, @"..\..\..\Android\Docs\xml"));
                    var forwardAssembliesFolder = Path.GetFullPath(Path.Combine(assemblyFolder, @"..\..\..\..\Sources\Framework\ForwardAssemblies"));
                    //var sdkRoot = Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT");
                    if (string.IsNullOrEmpty(sdkRoot))
                    {
                        throw new ArgumentException("Set ANDROID_SDK_ROOT environment variable");
                    }
                    var platformFolder = Path.Combine(sdkRoot, @"platforms\android-15");
                    args = new[] {
                        ToolOptions.InputJar.CreateArg(Path.Combine(platformFolder, "Android.jar")),
                        ToolOptions.InputAttrsXml.CreateArg(Path.Combine(platformFolder, @"data\res\values\attrs.xml")),
                        ToolOptions.InputSourceProperties.CreateArg(Path.Combine(platformFolder, "source.properties")),
                        ToolOptions.OutputFolder.CreateArg(folder),
                        //ToolOptions.DoxygenXmlFolder.CreateArg(xmlFolder),
                        //ToolOptions.PublicKeyToken.CreateArg("0a72796057571e65"),
                        ToolOptions.ForwardAssembliesFolder.CreateArg(forwardAssembliesFolder)
                    };
                }
#endif

                var options = new CommandLineOptions(args);
                if (options.ShowHelp)
                {
                    options.Usage();
                    return(2);
                }

                if (!File.Exists(options.FrameworkJar))
                {
                    throw new ArgumentException(string.Format("Framework jar ({0}) not found.", options.FrameworkJar));
                }

                if (!File.Exists(options.SourceProperties))
                {
                    throw new ArgumentException(string.Format("Source.properties ({0}) not found.", options.SourceProperties));
                }
                var sdkPropertiesPath = Path.Combine(Path.GetDirectoryName(options.SourceProperties), "sdk.properties");
                if (!File.Exists(sdkPropertiesPath))
                {
                    throw new ArgumentException(string.Format("sdk.properties ({0}) not found.", sdkPropertiesPath));
                }

                // Load source.properties
                var sourceProperties = new SourceProperties(options.SourceProperties);

                using (var jf = new JarFile(File.Open(options.FrameworkJar, FileMode.Open, FileAccess.Read), AttributeConstants.Dot42Scope, null))
                {
                    // Create output folder
                    var folder = Path.Combine(options.OutputFolder, sourceProperties.PlatformVersion);
                    Directory.CreateDirectory(folder);

                    if (!options.VersionOnly)
                    {
                        // Load Doxygen model
                        var xmlModel = new DocModel();
                        using (Profiler.Profile(x => Console.WriteLine("Load XML took {0}ms", x.TotalMilliseconds)))
                        {
                            xmlModel.Load(options.DoxygenXmlFolder);
                        }

                        // Create mscorlib
                        CreateFrameworkAssembly(jf, xmlModel, sourceProperties, folder);

                        // Copy AndroidManifest.xml into the assembly.
                        var manifestStream = jf.GetResource("AndroidManifest.xml");

                        // Copy resources.arsc into the assembly.
                        var resourcesStream = jf.GetResource("resources.arsc");

                        // Load attrs.xml into memory
                        var attrsXml = File.ReadAllBytes(options.AttrsXml);

                        // Load layout.xml into memory
                        var layoutXml = File.ReadAllBytes(Path.Combine(folder, "layout.xml"));

                        // Create base package
                        var basePackagePath = Path.Combine(folder, "base.apk");
                        using (var fileStream = new FileStream(basePackagePath, FileMode.Create, FileAccess.Write))
                        {
                            using (var zipStream = new ZipOutputStream(fileStream)
                            {
                                UseZip64 = UseZip64.Off
                            })
                            {
                                zipStream.SetLevel(9);

                                zipStream.PutNextEntry(new ZipEntry("AndroidManifest.xml")
                                {
                                    CompressionMethod = CompressionMethod.Deflated
                                });
                                zipStream.Write(manifestStream, 0, manifestStream.Length);
                                zipStream.CloseEntry();

                                zipStream.PutNextEntry(new ZipEntry("resources.arsc")
                                {
                                    CompressionMethod = CompressionMethod.Deflated
                                });
                                zipStream.Write(resourcesStream, 0, resourcesStream.Length);
                                zipStream.CloseEntry();

                                zipStream.PutNextEntry(new ZipEntry(@"attrs.xml")
                                {
                                    CompressionMethod = CompressionMethod.Deflated
                                });
                                zipStream.Write(attrsXml, 0, attrsXml.Length);
                                zipStream.CloseEntry();

                                zipStream.PutNextEntry(new ZipEntry(@"layout.xml")
                                {
                                    CompressionMethod = CompressionMethod.Deflated
                                });
                                zipStream.Write(layoutXml, 0, layoutXml.Length);
                                zipStream.CloseEntry();
                            }
                        }

                        // Create output folder file
                        if (!string.IsNullOrEmpty(options.OutputFolderFile))
                        {
                            File.WriteAllText(options.OutputFolderFile, folder);
                        }
                    }

                    // Create output version file
                    var version =
                        string.Format(File.ReadAllText(Path.Combine(folder, "..", "..", "Header.txt")), "Version.cs") + Environment.NewLine +
                        string.Format("[assembly: System.Reflection.AssemblyVersion(\"{0}\")]", sourceProperties.AssemblyVersion) + Environment.NewLine +
                        string.Format("[assembly: System.Reflection.AssemblyFileVersion(\"{0}\")]", sourceProperties.AssemblyFileVersion) + Environment.NewLine +
                        string.Format("[assembly: System.Reflection.AssemblyInformationalVersion(\"{0}\")]", sourceProperties.AssemblyInformationalVersion) + Environment.NewLine +
                        "#if !BASELIB" + Environment.NewLine +
                        string.Format("[assembly: System.Runtime.Versioning.TargetFramework(\"Dot42,Version={0}\", FrameworkDisplayName = \"Dot42\")]", sourceProperties.PlatformVersion) + Environment.NewLine +
                        "#endif" + Environment.NewLine;
                    File.WriteAllText(Path.Combine(folder, "Version.cs"), version);

                    if (!options.VersionOnly)
                    {
                        // Load sdk.properties
                        var sdkProperties = new SdkProperties(sdkPropertiesPath);

                        // Create framework ini
                        var frameworkIni = new FrameworkIni(folder);
                        Initialize(frameworkIni, sourceProperties, sdkProperties);
                        frameworkIni.Save();

                        // Create FrameworkList.xml
                        FrameworkListBuilder.Build(folder, options.ForwardAssembliesFolder, null,
                                                   sourceProperties.AssemblyVersion, sourceProperties.PlatformVersion);
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
#if DEBUG
                Console.WriteLine(ex.StackTrace);
#endif
                return(1);
            }
        }