Esempio n. 1
0
        /// <summary>
        /// Converts the top folder to a string.
        /// </summary>
        private bool FolderToString(TopFolder topFolder, out string path)
        {
            switch (topFolder)
            {
            case TopFolder.Root:
                path = "";
                return(false);

            case TopFolder.Base:
                path = "BaseDAT";
                return(true);

            case TopFolder.View:
                path = "Views";
                return(true);

            case TopFolder.Server:
                path = "ScadaServer";
                return(true);

            case TopFolder.Comm:
                path = "ScadaComm";
                return(true);

            case TopFolder.Web:
                path = "ScadaWeb";
                return(true);

            case TopFolder.Agent:
                path = agentShortDir;
                return(true);

            default:
                throw new ScadaException("Top folder {0} not supported.", topFolder);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Downloads the configuration part to the file.
        /// </summary>
        public void DownloadConfig(string destFileName, TopFolder topFolder)
        {
            if (destFileName == null)
            {
                throw new ArgumentNullException(nameof(destFileName));
            }

            RelativePath relativePath;
            string       shortFileName = Path.GetFileName(destFileName);

            if (!shortFileName.StartsWith(AgentConst.DownloadConfigPrefix))
            {
                throw new ArgumentException("Invalid file name.", nameof(destFileName));
            }

            switch (topFolder)
            {
            case TopFolder.Base:
            case TopFolder.View:
                relativePath = new RelativePath(topFolder, AppFolder.Root, shortFileName);
                break;

            case TopFolder.Server:
            case TopFolder.Comm:
            case TopFolder.Web:
                relativePath = new RelativePath(topFolder, AppFolder.Config, shortFileName);
                break;

            default:
                throw new ScadaException(Locale.IsRussian ?
                                         "Невозможно определить файлы для скачивания." :
                                         "Unable to define files to download.");
            }

            DownloadFile(relativePath, destFileName, true);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public RelativePath(TopFolder topFolder, AppFolder appFolder, string path = "")
 {
     TopFolder = topFolder;
     AppFolder = appFolder;
     Path      = path ?? "";
 }
        /// <summary>
        /// Generate fast transfer stream data.
        /// </summary>
        /// <param name="serverId">server id.</param>
        /// <param name="buffer">Input buffer data.</param>
        /// <returns>AbstractFastTransferStream object.</returns>
        private AbstractFastTransferStream GenerateAbstractFastTransferStream(
            int serverId,
            byte[] buffer)
        {
            using (FastTransferStream fs = new FastTransferStream(buffer, false))
            {
                AbstractFastTransferStream afts;

                // Record all property list generated while deserializing.
                SyntacticalBase.AllPropList = new List<PropList>();
                int icsStateIndex = -1;
                switch (this.streamType)
                {
                    case FastTransferStreamType.state:
                        State s = new State(fs);
                        this.VerifyMarkers(s);

                        // Insert state to the ICSStateContainer
                        icsStateIndex = this.InsertStateDict(s);
                        afts = new AbstractFastTransferStream();

                        // Get the AbstractState corresponding to the state from the fast transfer stream.
                        AbstractState astate = this.GetAbstractState(serverId, icsStateIndex, s);

                        // Set the AbstractState of the AbstractFastTransferStream.
                        afts.AbstractState = new AbstractState
                        {
                            AbstractICSStateIndex = icsStateIndex,
                            IdSetGiven = astate.IdSetGiven
                        };

                        //// Other fields of the AbstractState of the AbstractFastTransferStream do not need.

                        afts.StreamType = FastTransferStreamType.state;
                        return afts;
                    case FastTransferStreamType.attachmentContent:
                        AttachmentContent att = new AttachmentContent(fs);
                        this.VerifyMarkers(att);
                        return att.GetAbstractFastTransferStream();
                    case FastTransferStreamType.contentsSync:
                        ContentsSync cs = new ContentsSync(fs);
                        this.VerifyMarkers(cs);

                        // Insert the state of the contentsSync to the ICSStateContainer
                        icsStateIndex = this.InsertStateDict(cs.State);
                        afts = this.GetAbstractContentSync(
                            serverId, icsStateIndex, cs);
                        return afts;
                    case FastTransferStreamType.folderContent:
                        FolderContent fc = new FolderContent(fs);
                        this.VerifyMarkers(fc);
                        this.VerifyFolderReplicaInfoStructure(fc);

                        afts = fc.GetAbstractFastTransferStream();

                        if (!this.existNoPermissionFolder)
                        {
                            afts.AbstractFolderContent.IsNoPermissionObjNotOut = false;
                        }

                        this.VerifyMetaProperty(afts);
                        return afts;
                    case FastTransferStreamType.hierarchySync:
                        HierarchySync hs = new HierarchySync(fs);
                        this.VerifyMarkers(hs);
                        if (hs.FolderChangeList.Count > 0)
                        {
                            PropValue property = hs.FolderChangeList[hs.FolderChangeList.Count - 1].PropList.PropValues.Find(p => p.PropInfo.PropID == 0x65e3);
                            if (property != null)
                            {
                                this.lastConflictInfo.PCLXFromServer = ((VarPropTypePropValue)property).ValueArray;
                                this.VerifyPidTagPredecessorChangeList();
                            }
                        }

                        // Insert state to the ICSStateContainer
                        icsStateIndex = this.InsertStateDict(hs.State);
                        afts = this.GetAbstractHierachySync(serverId, hs, icsStateIndex);
                        return afts;
                    case FastTransferStreamType.MessageContent:
                        MessageContent mc = new MessageContent(fs);
                        for (int i = 0; i < mc.PropList.PropValues.Count; i++)
                        {
                            PropValue propValue = mc.PropList.PropValues[i];

                            if (propValue.PropType == 0x84b0)
                            {
                                CodePage codePage = new CodePage();
                                codePage.Deserialize(propValue.PropType);

                                this.VerifyCodePageProperty(codePage);
                            }
                        }

                        this.VerifyMarkers(mc);
                        afts = mc.GetAbstractFastTransferStream();
                        this.VerifyMetaProperty(afts);
                        return afts;
                    case FastTransferStreamType.MessageList:
                        MessageList ml = new MessageList(fs);
                        afts = ml.GetAbstractFastTransferStream();
                        this.VerifyMetaProperty(afts);
                        this.VerifyMarkers(ml);
                        return afts;
                    case FastTransferStreamType.TopFolder:
                        TopFolder tf = new TopFolder(fs);
                        this.VerifyMarkers(tf);
                        afts = tf.GetAbstractFastTransferStream();
                        this.VerifyMetaProperty(afts);
                        return afts;
                    default:
                        AdapterHelper.Site.Assert.Fail("The stream type is invalid, its value is:{0}.", this.streamType);
                        return new AbstractFastTransferStream();
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public RelativePath(TopFolder topFolder, AppFolder appFolder, string path = "")
 {
     DirectoryID = (byte)topFolder | ((byte)appFolder << 8);
     Path        = path ?? "";
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public RelativePath(TopFolder topFolder)
 {
     DirectoryID = (byte)topFolder;
     Path        = "";
 }